+ /**
+ * If the select returned <= 0 then it failed due to an error
+ * or timeout so this thread could stop if asked to do so.
+ * Anything else means it needs to continue unless the system is shutting down
+ */
+ if (ret <= 0)
+ {
+ /**
+ * select says nothing to do so we can change to running if we haven't been asked to stop.
+ */
+ ctdl_thread_internal_change_state(CT, CTDL_THREAD_RUNNING);
+ }
+ else
+ {
+ /**
+ * The select says this thread needs to do something useful.
+ * This thread was in an idle state so it may have been asked to stop
+ * but if the system isn't shutting down this thread is no longer
+ * idle and select has given it a task to do so it must not stop
+ * In this condition we need to force it into the running state.
+ * CtdlThreadGC will clear its ticker for us.
+ */
+ if (GC_thread->state > CTDL_THREAD_STOP_REQ)
+ {
+ citthread_mutex_lock(&CT->ThreadMutex); /* To prevent race condition of a sleeping thread */
+ CT->state = CTDL_THREAD_RUNNING;
+ citthread_mutex_unlock(&CT->ThreadMutex);
+ }
+ }
+