Added SILC Rand API, SILC Global Variables API and silcruntime.h.in
[runtime.git] / lib / silcutil / silcthread.c
index 3ada012c14e86c3c264c0f275a0476fbd1f2d523..c8507034e1eb9900f4c40a33fb82c56659ffaa8b 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2007 Pekka Riikonen
+  Copyright (C) 2007 - 2008 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
 
 */
 
-#include "silc.h"
+#include "silcruntime.h"
 
 /***************************** Thread Pool API *****************************/
 
@@ -319,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);
@@ -411,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;
   }
 
@@ -422,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;
       }
 
@@ -577,6 +585,8 @@ void silc_thread_pool_purge(SilcThreadPool tp)
 
 /*************************** Thread-local Storage ***************************/
 
+/* Set Tls context */
+
 void silc_thread_tls_set(void *context)
 {
   SilcTls tls = silc_thread_get_tls();
@@ -591,6 +601,8 @@ void silc_thread_tls_set(void *context)
   tls->thread_context = context;
 }
 
+/* Get Tls context */
+
 void *silc_thread_tls_get(void)
 {
   SilcTls tls = silc_thread_get_tls();