diff options
| -rw-r--r-- | libglusterfs/src/mem-pool.c | 33 | ||||
| -rw-r--r-- | libglusterfs/src/mem-pool.h | 1 | 
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);  | 
