1 /* SilcThreadPool tests */
7 static void func(SilcSchedule schedule, void *context)
9 silc_thread_tls_set(context);
10 SILC_LOG_DEBUG(("func: %d", (int)silc_thread_tls_get()));
14 SILC_TASK_CALLBACK(compl)
16 SILC_LOG_DEBUG(("completion: %d", (int)context));
17 if ((int)context == 0xff)
18 silc_schedule_stop(schedule);
21 int main(int argc, char **argv)
23 SilcBool success = FALSE;
27 if (argc > 1 && !strcmp(argv[1], "-d")) {
30 silc_log_debug_hexdump(TRUE);
31 silc_log_set_debug_string("*thread*,*errno*");
34 schedule = silc_schedule_init(0, NULL, NULL);
38 SILC_LOG_DEBUG(("Allocate thread pool"));
39 tp = silc_thread_pool_alloc(NULL, 2, 4, TRUE);
42 SILC_LOG_DEBUG(("Stop thread pool"));
43 silc_thread_pool_free(tp, TRUE);
46 SILC_LOG_DEBUG(("Allocate thread pool"));
47 tp = silc_thread_pool_alloc(NULL, 0, 2, FALSE);
50 for (i = 0; i < 6; i++) {
51 SILC_LOG_DEBUG(("Run thread %d", i + 1));
52 if (!silc_thread_pool_run(tp, TRUE, NULL, func, (void *) i + 1,
53 compl, (void *)i + 1))
57 SILC_LOG_DEBUG(("Stop thread pool"));
58 silc_thread_pool_free(tp, TRUE);
60 SILC_LOG_DEBUG(("Allocate thread pool"));
61 tp = silc_thread_pool_alloc(NULL, 0, 2, TRUE);
64 for (i = 0; i < 2; i++) {
65 SILC_LOG_DEBUG(("Run thread %d", i + 1));
66 if (!silc_thread_pool_run(tp, FALSE, NULL, func, (void *) i + 1,
67 compl, (void *)i + 1))
70 if (silc_thread_pool_run(tp, FALSE, NULL, func, (void *)3,
74 SILC_LOG_DEBUG(("Stop thread pool"));
75 silc_thread_pool_free(tp, TRUE);
77 SILC_LOG_DEBUG(("Allocate thread pool"));
78 tp = silc_thread_pool_alloc(NULL, 3, 20, TRUE);
81 for (i = 0; i < 8; i++) {
82 SILC_LOG_DEBUG(("Run thread %d", i + 1));
83 if (!silc_thread_pool_run(tp, FALSE, schedule, func, (void *) i + 1,
84 compl, (void *)i + 1))
87 if (!silc_thread_pool_run(tp, FALSE, schedule, func, (void *)0xff,
92 silc_thread_pool_purge(tp);
94 silc_schedule(schedule);
96 SILC_LOG_DEBUG(("Stop thread pool"));
97 silc_thread_pool_free(tp, TRUE);
99 silc_schedule_uninit(schedule);
103 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
104 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");