X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=citadel%2Fsysdep.c;fp=citadel%2Fsysdep.c;h=4ea07f3edcd95ffc34802439689098d83d7245c8;hp=1caf2ce10b403987d9d8e53df1a3f89cafe44dd7;hb=f2f392abe416b03750cb053fd0780f62c85d3ae4;hpb=5ce143deec653885c56c978b03acea9265477297 diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 1caf2ce10..4ea07f3ed 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,22 @@ 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--; + 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); }