+
+ /* Reduce the size of the worker thread pool if necessary. */
+ if ((CtdlThreadGetWorkers() > config.c_min_workers) && (CtdlThreadWorkerAvg < 20))
+ {
+ /* Ask a worker thread to stop as we no longer need it */
+ begin_critical_section(S_THREAD_LIST);
+ last_worker = CtdlThreadList;
+ while (last_worker)
+ {
+ if (last_worker->flags & CTDLTHREAD_WORKER && last_worker->state > CTDL_THREAD_STOPPING)
+ break;
+ else
+ last_worker = last_worker->next;
+ }
+ end_critical_section(S_THREAD_LIST);
+ if (last_worker)
+ {
+#ifdef WITH_THREADLOG
+ CtdlLogPrintf(CTDL_DEBUG, "Thread system, stopping excess worker thread \"%s\" (%ld).\n",
+ last_worker->name,
+ last_worker->tid
+ );
+#endif
+ CtdlThreadStop(last_worker);
+// ctdl_thread_internal_change_state (last_worker, CTDL_THREAD_STOP_REQ);
+// pthread_mutex_lock(&last_worker->ThreadMutex);
+// pthread_cond_signal(&last_worker->ThreadCond);
+// pthread_mutex_unlock(&last_worker->ThreadMutex);
+ }
+ }
+
+