1 /* SilcThreadPool tests */
7 static void func(SilcSchedule schedule, void *context)
9 SILC_LOG_DEBUG(("func: %d", (int)context));
13 SILC_TASK_CALLBACK(compl)
15 SILC_LOG_DEBUG(("completion: %d", (int)context));
16 if ((int)context == 0xff)
17 silc_schedule_stop(schedule);
20 int main(int argc, char **argv)
22 SilcBool success = FALSE;
26 if (argc > 1 && !strcmp(argv[1], "-d")) {
29 silc_log_debug_hexdump(TRUE);
30 silc_log_set_debug_string("*thread*");
33 schedule = silc_schedule_init(0, NULL, NULL);
37 SILC_LOG_DEBUG(("Allocate thread pool"));
38 tp = silc_thread_pool_alloc(NULL, 2, 4, TRUE);
41 SILC_LOG_DEBUG(("Stop thread pool"));
42 silc_thread_pool_free(tp, TRUE);
45 SILC_LOG_DEBUG(("Allocate thread pool"));
46 tp = silc_thread_pool_alloc(NULL, 0, 2, FALSE);
49 for (i = 0; i < 6; i++) {
50 SILC_LOG_DEBUG(("Run thread %d", i + 1));
51 if (!silc_thread_pool_run(tp, TRUE, NULL, func, (void *) i + 1,
52 compl, (void *)i + 1))
56 SILC_LOG_DEBUG(("Stop thread pool"));
57 silc_thread_pool_free(tp, TRUE);
59 SILC_LOG_DEBUG(("Allocate thread pool"));
60 tp = silc_thread_pool_alloc(NULL, 0, 2, TRUE);
63 for (i = 0; i < 2; i++) {
64 SILC_LOG_DEBUG(("Run thread %d", i + 1));
65 if (!silc_thread_pool_run(tp, FALSE, NULL, func, (void *) i + 1,
66 compl, (void *)i + 1))
69 if (silc_thread_pool_run(tp, FALSE, NULL, func, (void *)3,
73 SILC_LOG_DEBUG(("Stop thread pool"));
74 silc_thread_pool_free(tp, TRUE);
76 SILC_LOG_DEBUG(("Allocate thread pool"));
77 tp = silc_thread_pool_alloc(NULL, 3, 20, TRUE);
80 for (i = 0; i < 8; i++) {
81 SILC_LOG_DEBUG(("Run thread %d", i + 1));
82 if (!silc_thread_pool_run(tp, FALSE, schedule, func, (void *) i + 1,
83 compl, (void *)i + 1))
86 if (!silc_thread_pool_run(tp, FALSE, schedule, func, (void *)0xff,
91 silc_thread_pool_purge(tp);
93 silc_schedule(schedule);
95 SILC_LOG_DEBUG(("Stop thread pool"));
96 silc_thread_pool_free(tp, TRUE);
98 silc_schedule_uninit(schedule);
102 SILC_LOG_DEBUG(("Testing was %s", success ? "SUCCESS" : "FAILURE"));
103 fprintf(stderr, "Testing was %s\n", success ? "SUCCESS" : "FAILURE");