summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@fb.com>2017-06-30 07:07:16 -0700
committerJeff Darcy <jeff@pl.atyp.us>2017-07-01 02:56:14 +0000
commit5a67bc07db128782024ccb7c8ec3a35a8542e540 (patch)
tree07424082b57411de65537aae745f361834847da5
parentb4db625d0ccb4fdc6537ed9f6e8ebeaffd1c4873 (diff)
libglusterfs: add mem_pools_fini
This also makes mem_pools_init and mem_pools_fini re-callable, so GFAPI can go through infinite init/fini cycles if they want to. Not saying that's a good idea, but at least it's safe. Change-Id: I617913410bcff54568b802cb653f48bdd533bd65 Signed-off-by: Jeff Darcy <jdarcy@fb.com> Reviewed-on: https://review.gluster.org/17662 Smoke: Gluster Build System <jenkins@build.gluster.org> Tested-by: Jeff Darcy <jeff@pl.atyp.us> Reviewed-by: Niels de Vos <ndevos@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Jeff Darcy <jeff@pl.atyp.us>
-rw-r--r--libglusterfs/src/mem-pool.c33
-rw-r--r--libglusterfs/src/mem-pool.h1
2 files changed, 29 insertions, 5 deletions
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 8bed0a558b8..e116437583e 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -463,6 +463,7 @@ pool_sweeper (void *arg)
for (;;) {
sleep (POOL_SWEEP_SECS);
+ (void) pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
INIT_LIST_HEAD (&state.death_row);
state.n_cold_lists = 0;
@@ -498,6 +499,7 @@ pool_sweeper (void *arg)
for (i = 0; i < state.n_cold_lists; ++i) {
free_obj_list (state.cold_lists[i]);
}
+ (void) pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL);
}
}
@@ -539,16 +541,37 @@ mem_pools_preinit (void)
+ sizeof (per_thread_pool_t) * (NPOOLS - 1);
}
+#if !defined(GF_DISABLE_MEMPOOL)
+static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
+static unsigned int init_count = 0;
+static pthread_t sweeper_tid;
+
void
mem_pools_init (void)
{
-#if !defined(GF_DISABLE_MEMPOOL)
- pthread_t kid;
+ pthread_mutex_lock (&init_mutex);
+ if ((init_count++) == 0) {
+ (void) pthread_create (&sweeper_tid, NULL, pool_sweeper, NULL);
+ }
+ pthread_mutex_unlock (&init_mutex);
+}
- (void) pthread_create (&kid, NULL, pool_sweeper, NULL);
- (void) pthread_detach (kid);
-#endif
+void
+mem_pools_fini (void)
+{
+ pthread_mutex_lock (&init_mutex);
+ GF_ASSERT (init_count > 0);
+ if ((--init_count) == 0) {
+ (void) pthread_cancel (sweeper_tid);
+ (void) pthread_join (sweeper_tid, NULL);
+ }
+ pthread_mutex_unlock (&init_mutex);
}
+
+#else
+void mem_pools_init (void) {}
+void mem_pools_fini (void) {}
+#endif
struct mem_pool *
mem_pool_new_fn (unsigned long sizeof_type,
diff --git a/libglusterfs/src/mem-pool.h b/libglusterfs/src/mem-pool.h
index 1b8132bf315..5ae411fd3d6 100644
--- a/libglusterfs/src/mem-pool.h
+++ b/libglusterfs/src/mem-pool.h
@@ -257,6 +257,7 @@ struct mem_pool {
};
void mem_pools_init (void);
+void mem_pools_fini (void);
struct mem_pool *
mem_pool_new_fn (unsigned long sizeof_type, unsigned long count, char *name);