Added SILC Thread Queue API
[silc.git] / lib / silcutil / tests / test_silcthread.c
index 920cb6f9de94cf72e578f10774e6c23fab6f9078..da078b3e8af34b79a7bfa783b79e08720bb149ec 100644 (file)
@@ -6,11 +6,12 @@ SilcSchedule schedule;
 
 static void func(SilcSchedule schedule, void *context)
 {
-  SILC_LOG_DEBUG(("func: %d", (int)context));
+  silc_thread_tls_set(context);
+  SILC_LOG_DEBUG(("func: %d", (int)silc_thread_tls_get()));
   sleep(1);
 }
 
-static void compl(SilcSchedule schedule, void *context)
+SILC_TASK_CALLBACK(compl)
 {
   SILC_LOG_DEBUG(("completion: %d", (int)context));
   if ((int)context == 0xff)
@@ -27,10 +28,10 @@ int main(int argc, char **argv)
     silc_log_debug(TRUE);
     silc_log_quick(TRUE);
     silc_log_debug_hexdump(TRUE);
-    silc_log_set_debug_string("*thread*");
+    silc_log_set_debug_string("*thread*,*errno*");
   }
 
-  schedule = silc_schedule_init(0, NULL);
+  schedule = silc_schedule_init(0, NULL, NULL);
   if (!schedule)
     goto err;
 
@@ -43,16 +44,16 @@ int main(int argc, char **argv)
 
 
   SILC_LOG_DEBUG(("Allocate thread pool"));
-  tp = silc_thread_pool_alloc(NULL, 0, 2, TRUE);
+  tp = silc_thread_pool_alloc(NULL, 0, 2, FALSE);
   if (!tp)
     goto err;
-  for (i = 0; i < 4; i++) {
+  for (i = 0; i < 6; i++) {
     SILC_LOG_DEBUG(("Run thread %d", i + 1));
     if (!silc_thread_pool_run(tp, TRUE, NULL, func, (void *) i + 1,
                              compl, (void *)i + 1))
       goto err;
   }
-  sleep(3);
+  sleep(6);
   SILC_LOG_DEBUG(("Stop thread pool"));
   silc_thread_pool_free(tp, TRUE);
 
@@ -74,7 +75,7 @@ int main(int argc, char **argv)
   silc_thread_pool_free(tp, TRUE);
 
   SILC_LOG_DEBUG(("Allocate thread pool"));
-  tp = silc_thread_pool_alloc(NULL, 8, 16, FALSE);
+  tp = silc_thread_pool_alloc(NULL, 3, 20, TRUE);
   if (!tp)
     goto err;
   for (i = 0; i < 8; i++) {
@@ -86,6 +87,9 @@ int main(int argc, char **argv)
   if (!silc_thread_pool_run(tp, FALSE, schedule, func, (void *)0xff,
                            compl, (void *)0xff))
     goto err;
+  sleep(1);
+
+  silc_thread_pool_purge(tp);
 
   silc_schedule(schedule);