X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fsysdep.c;h=01e7e831d49ddcd5de11b260bac2e02e29c60acd;hb=3367e0fa984b3e5f61b2f75f07fc4e11f824bb73;hp=1caf2ce10b403987d9d8e53df1a3f89cafe44dd7;hpb=5ce143deec653885c56c978b03acea9265477297;p=citadel.git diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 1caf2ce10..01e7e831d 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -1157,7 +1157,9 @@ void *worker_thread(void *blah) { CitContext *con = NULL; /* Temporary context pointer */ int i; + pthread_mutex_lock(&ThreadCountMutex); ++num_workers; + pthread_mutex_unlock(&ThreadCountMutex); while (!server_shutting_down) { @@ -1339,7 +1341,10 @@ do_select: force_purge = 0; SKIP_SELECT: /* We're bound to a session */ + pthread_mutex_lock(&ThreadCountMutex); ++active_workers; + pthread_mutex_unlock(&ThreadCountMutex); + if (bind_me != NULL) { become_session(bind_me); @@ -1373,11 +1378,23 @@ SKIP_SELECT: dead_session_purge(force_purge); do_housekeeping(); + + pthread_mutex_lock(&ThreadCountMutex); --active_workers; + if ((active_workers + config.c_min_workers < num_workers) && + (num_workers > config.c_min_workers)) + { + num_workers--; + pthread_mutex_unlock(&ThreadCountMutex); + return (NULL); + } + pthread_mutex_unlock(&ThreadCountMutex); } /* If control reaches this point, the server is shutting down */ + pthread_mutex_lock(&ThreadCountMutex); --num_workers; + pthread_mutex_unlock(&ThreadCountMutex); return(NULL); }