+ stop:
+ /* Stop the thread. Remove from threads list. */
+ SILC_LOG_DEBUG(("Stop thread %p", t));
+
+ /* We can unlock the thread now. After we get the thread pool lock
+ no one can retrieve the thread anymore. */
+ silc_mutex_unlock(lock);
+ silc_mutex_lock(tp->lock);
+
+ silc_list_del(tp->threads, t);
+ silc_list_start(tp->threads);
+
+ /* Clear thread's call queue. */
+ silc_list_start(t->queue);
+ silc_list_start(t->free_queue);
+ while ((q = silc_list_get(t->queue)))
+ silc_sfree(tp->stack, q);
+ while ((q = silc_list_get(t->free_queue)))
+ silc_sfree(tp->stack, q);
+
+ /* Destroy the thread */
+ silc_mutex_free(lock);
+ silc_cond_free(thread_signal);
+ silc_sfree(tp->stack, t);
+
+ /* If we are last thread, signal the waiting destructor. */
+ if (silc_list_count(tp->threads) == 0)
+ silc_cond_signal(tp->pool_signal);
+
+ /* Release pool reference. Releases lock also. */
+ silc_thread_pool_unref(tp);
+