X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilcthread.c;h=8e51a15d13ef4c182382cf029f3b0f41512c3deb;hb=e7b6c157b80152bf9fb9266e6bdd93f9fb0db776;hp=794259c78dc11eab00bd71d39679053c0dabc988;hpb=20a4530c0db6d4317d8a9952edd1655e10b83844;p=silc.git diff --git a/lib/silcutil/silcthread.c b/lib/silcutil/silcthread.c index 794259c7..8e51a15d 100644 --- a/lib/silcutil/silcthread.c +++ b/lib/silcutil/silcthread.c @@ -19,6 +19,8 @@ #include "silc.h" +/***************************** Thread Pool API *****************************/ + /* Explanation of the thread pool execution. When new call is added to thread pool by calling silc_thread_pool_run @@ -317,10 +319,16 @@ SilcThreadPool silc_thread_pool_alloc(SilcStack stack, SilcThreadPool tp; int i; - if (max_threads < min_threads) + if (max_threads < min_threads) { + silc_set_errno_reason(SILC_ERR_INVALID_ARGUMENT, + "Max threads is smaller than min threads (%d < %d)", + max_threads, min_threads); return NULL; - if (!max_threads) + } + if (!max_threads) { + silc_set_errno_reason(SILC_ERR_INVALID_ARGUMENT, "Max threads is 0"); return NULL; + } if (stack) stack = silc_stack_alloc(0, stack); @@ -409,6 +417,7 @@ SilcBool silc_thread_pool_run(SilcThreadPool tp, if (tp->destroy) { silc_mutex_unlock(tp->lock); + silc_set_errno(SILC_ERR_NOT_VALID); return FALSE; } @@ -420,6 +429,7 @@ SilcBool silc_thread_pool_run(SilcThreadPool tp, /* Maximum threads reached */ if (!queuable) { silc_mutex_unlock(tp->lock); + silc_set_errno(SILC_ERR_LIMIT); return FALSE; } @@ -572,3 +582,27 @@ void silc_thread_pool_purge(SilcThreadPool tp) silc_list_start(tp->threads); silc_mutex_unlock(tp->lock); } + +/*************************** Thread-local Storage ***************************/ + +void silc_thread_tls_set(void *context) +{ + SilcTls tls = silc_thread_get_tls(); + + if (!tls) { + /* Initialize Tls for this thread */ + tls = silc_thread_tls_init(); + if (!tls) + return; + } + + tls->thread_context = context; +} + +void *silc_thread_tls_get(void) +{ + SilcTls tls = silc_thread_get_tls(); + if (!tls) + return NULL; + return tls->thread_context; +}