From: Hallvard Furuseth Date: Mon, 10 Mar 2008 13:21:24 +0000 (+0000) Subject: ITS#5407 cleanup (make pool_pause & pool_pausecheck wrappers for handle_pause) X-Git-Tag: OPENLDAP_REL_ENG_2_4_9~20^2~102 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=00be5652642c4b858cb48692db12e26d2e2c0833;p=openldap ITS#5407 cleanup (make pool_pause & pool_pausecheck wrappers for handle_pause) --- diff --git a/libraries/libldap_r/tpool.c b/libraries/libldap_r/tpool.c index f03f3c4178..fa22d7d9a4 100644 --- a/libraries/libldap_r/tpool.c +++ b/libraries/libldap_r/tpool.c @@ -692,12 +692,8 @@ ldap_int_thread_pool_wrapper ( return(NULL); } -/* See if a pause was requested; wait for it if so. - * Return 1 if we waited, 0 if not - */ -int -ldap_pvt_thread_pool_pausecheck ( - ldap_pvt_thread_pool_t *tpool ) +static int +handle_pause( ldap_pvt_thread_pool_t *tpool, int do_pause ) { struct ldap_int_thread_pool_s *pool; @@ -709,7 +705,7 @@ ldap_pvt_thread_pool_pausecheck ( if (pool == NULL) return(0); - if ( !pool->ltp_pause ) + if (! (do_pause || pool->ltp_pause)) return(0); ldap_pvt_thread_mutex_lock(&pool->ltp_mutex); @@ -727,56 +723,42 @@ ldap_pvt_thread_pool_pausecheck ( pool->ltp_pending_count--; pool->ltp_active_count++; } - ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); - return 1; -} -/* Pause the pool. Return when all other threads are paused. */ -int -ldap_pvt_thread_pool_pause ( - ldap_pvt_thread_pool_t *tpool ) -{ - struct ldap_int_thread_pool_s *pool; - - if (tpool == NULL) - return(-1); - - pool = *tpool; - - if (pool == NULL) - return(0); - - ldap_pvt_thread_mutex_lock(&pool->ltp_mutex); + if (do_pause) { + /* Wait for everyone else to pause or finish */ + pool->ltp_pause = 1; + /* Let ldap_pvt_thread_pool_submit() through to its ltp_pause test, + * and do not finish threads in ldap_pvt_thread_pool_wrapper() */ + pool->ltp_open_count = -pool->ltp_open_count; + SET_VARY_OPEN_COUNT(pool); + /* Hide pending tasks from ldap_pvt_thread_pool_wrapper() */ + pool->ltp_work_list = &empty_pending_list; - /* If someone else has already requested a pause, we have to wait */ - if (pool->ltp_pause) { - pool->ltp_pending_count++; - pool->ltp_active_count--; - /* let the other pool_pause() know when it can proceed */ - if (pool->ltp_active_count < 2) - ldap_pvt_thread_cond_signal(&pool->ltp_pcond); - do { - ldap_pvt_thread_cond_wait(&pool->ltp_cond, &pool->ltp_mutex); - } while (pool->ltp_pause); - pool->ltp_pending_count--; - pool->ltp_active_count++; + while (pool->ltp_active_count > 1) { + ldap_pvt_thread_cond_wait(&pool->ltp_pcond, &pool->ltp_mutex); + } } - /* Wait for everyone else to pause or finish */ - pool->ltp_pause = 1; - /* Let ldap_pvt_thread_pool_submit() through to its ltp_pause test, - * and do not finish threads in ldap_pvt_thread_pool_wrapper() */ - pool->ltp_open_count = -pool->ltp_open_count; - SET_VARY_OPEN_COUNT(pool); - /* Hide pending tasks from ldap_pvt_thread_pool_wrapper() */ - pool->ltp_work_list = &empty_pending_list; + ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); + return(!do_pause); +} - while (pool->ltp_active_count > 1) { - ldap_pvt_thread_cond_wait(&pool->ltp_pcond, &pool->ltp_mutex); - } +/* + * If a pause was requested, wait for it. If several threads + * are waiting to pause, let through one or more pauses. + * Return 1 if we waited, 0 if not, -1 at parameter error. + */ +int +ldap_pvt_thread_pool_pausecheck( ldap_pvt_thread_pool_t *tpool ) +{ + return handle_pause( tpool, 0 ); +} - ldap_pvt_thread_mutex_unlock(&pool->ltp_mutex); - return(0); +/* Pause the pool. Return when all other threads are paused. */ +int +ldap_pvt_thread_pool_pause( ldap_pvt_thread_pool_t *tpool ) +{ + return handle_pause( tpool, 1 ); } /* End a pause */