diff options
author | Poornima G <pgurusid@redhat.com> | 2015-02-18 21:40:46 +0530 |
---|---|---|
committer | Shyamsundar Ranganathan <srangana@redhat.com> | 2015-03-03 06:45:21 -0800 |
commit | 2acfbcf34ed77985905b2d122adbfd541eb01db1 (patch) | |
tree | 7af9b26759f2c9d5f863cbd1b5135888484fc630 /libglusterfs/src/event-poll.c | |
parent | 4ff398987805ba72010d328c61a5682088d32cf4 (diff) |
event_pool: Add the code to destroy the poller threads and event pool gracefully.
Change-Id: I49b6ceebb45773620c318fb5d20b81623db75ab6
BUG: 1093594
Signed-off-by: Poornima G <pgurusid@redhat.com>
Reviewed-on: http://review.gluster.org/9691
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
Diffstat (limited to 'libglusterfs/src/event-poll.c')
-rw-r--r-- | libglusterfs/src/event-poll.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/libglusterfs/src/event-poll.c b/libglusterfs/src/event-poll.c index c91fa8487b5..0daceb0d5a6 100644 --- a/libglusterfs/src/event-poll.c +++ b/libglusterfs/src/event-poll.c @@ -449,7 +449,24 @@ event_dispatch_poll (struct event_pool *event_pool) GF_VALIDATE_OR_GOTO ("event", event_pool, out); + pthread_mutex_lock (&event_pool->mutex); + { + event_pool->activethreadcount = 1; + } + pthread_mutex_unlock (&event_pool->mutex); + while (1) { + pthread_mutex_lock (&event_pool->mutex); + { + if (event_pool->destroy == 1) { + event_pool->activethreadcount = 0; + pthread_cond_broadcast (&event_pool->cond); + pthread_mutex_unlock (&event_pool->mutex); + return 0; + } + } + pthread_mutex_unlock (&event_pool->mutex); + size = event_dispatch_poll_resize (event_pool, ufds, size); ufds = event_pool->evcache; @@ -482,6 +499,31 @@ event_reconfigure_threads_poll (struct event_pool *event_pool, int value) return 0; } +/* This function is the destructor for the event_pool data structure + * Should be called only after poller_threads_destroy() is called, + * else will lead to crashes. + */ +static int +event_pool_destroy_poll (struct event_pool *event_pool) +{ + int ret = 0; + + ret = close (event_pool->breaker[0]); + if (ret) + return ret; + + ret = close (event_pool->breaker[1]); + if (ret) + return ret; + + event_pool->breaker[0] = event_pool->breaker[1] = -1; + + GF_FREE (event_pool->reg); + GF_FREE (event_pool); + + return ret; +} + struct event_ops event_ops_poll = { .new = event_pool_new_poll, .event_register = event_register_poll, @@ -489,5 +531,6 @@ struct event_ops event_ops_poll = { .event_unregister = event_unregister_poll, .event_unregister_close = event_unregister_close_poll, .event_dispatch = event_dispatch_poll, - .event_reconfigure_threads = event_reconfigure_threads_poll + .event_reconfigure_threads = event_reconfigure_threads_poll, + .event_pool_destroy = event_pool_destroy_poll }; |