1998-12-12 20:48:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1998 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-12-12 19:25:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
1998-08-17 22:05:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1998-10-22 01:33:20 +00:00
|
|
|
#include <isc/assertions.h>
|
1998-12-11 20:38:46 +00:00
|
|
|
#include <isc/mem.h>
|
1998-08-18 00:47:55 +00:00
|
|
|
#include <isc/task.h>
|
1998-08-18 19:28:30 +00:00
|
|
|
#include <isc/thread.h>
|
1998-10-16 01:18:31 +00:00
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/timer.h>
|
1998-08-18 19:28:30 +00:00
|
|
|
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_memctx_t *mctx = NULL;
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-10-21 01:13:50 +00:00
|
|
|
static isc_boolean_t
|
1998-12-13 23:45:21 +00:00
|
|
|
my_callback(isc_task_t *task, isc_event_t *event)
|
1998-08-18 00:29:57 +00:00
|
|
|
{
|
1998-08-17 23:15:50 +00:00
|
|
|
int i, j;
|
1998-08-19 23:36:12 +00:00
|
|
|
char *name = event->arg;
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-08-17 23:15:50 +00:00
|
|
|
j = 0;
|
1998-10-16 20:20:31 +00:00
|
|
|
for (i = 0; i < 1000000; i++)
|
1998-08-17 23:15:50 +00:00
|
|
|
j += 100;
|
1998-10-21 01:57:35 +00:00
|
|
|
printf("task %s (%p): %d\n", name, task, j);
|
1998-10-28 01:45:43 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
|
1998-10-21 01:13:50 +00:00
|
|
|
return (ISC_FALSE);
|
1998-08-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
|
1998-10-21 01:13:50 +00:00
|
|
|
static isc_boolean_t
|
1998-12-13 23:45:21 +00:00
|
|
|
my_shutdown(isc_task_t *task, isc_event_t *event) {
|
1998-08-19 23:36:12 +00:00
|
|
|
char *name = event->arg;
|
1998-08-17 23:15:50 +00:00
|
|
|
|
1998-10-21 01:57:35 +00:00
|
|
|
printf("shutdown %s (%p)\n", name, task);
|
1998-10-28 01:45:43 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
|
1998-10-21 01:13:50 +00:00
|
|
|
return (ISC_TRUE);
|
1998-08-17 22:05:58 +00:00
|
|
|
}
|
|
|
|
|
1998-10-21 01:13:50 +00:00
|
|
|
static isc_boolean_t
|
1998-12-13 23:45:21 +00:00
|
|
|
my_tick(isc_task_t *task, isc_event_t *event)
|
1998-08-18 19:28:30 +00:00
|
|
|
{
|
1998-08-19 23:36:12 +00:00
|
|
|
char *name = event->arg;
|
1998-08-18 19:28:30 +00:00
|
|
|
|
1998-10-13 20:22:22 +00:00
|
|
|
printf("task %p tick %s\n", task, name);
|
1998-10-28 01:45:43 +00:00
|
|
|
isc_event_free(&event);
|
|
|
|
|
1998-10-21 01:13:50 +00:00
|
|
|
return (ISC_FALSE);
|
1998-08-18 19:28:30 +00:00
|
|
|
}
|
|
|
|
|
1998-08-17 22:05:58 +00:00
|
|
|
void
|
1998-08-17 23:15:50 +00:00
|
|
|
main(int argc, char *argv[]) {
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_taskmgr_t *manager = NULL;
|
|
|
|
isc_task_t *t1 = NULL, *t2 = NULL;
|
|
|
|
isc_task_t *t3 = NULL, *t4 = NULL;
|
|
|
|
isc_event_t *event;
|
1998-08-17 23:15:50 +00:00
|
|
|
unsigned int workers;
|
1998-12-13 23:45:21 +00:00
|
|
|
isc_timermgr_t *timgr;
|
|
|
|
isc_timer_t *ti1, *ti2;
|
1998-10-23 23:00:40 +00:00
|
|
|
struct isc_time absolute;
|
|
|
|
struct isc_interval interval;
|
1998-08-17 23:15:50 +00:00
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
workers = atoi(argv[1]);
|
|
|
|
else
|
|
|
|
workers = 2;
|
|
|
|
printf("%d workers\n", workers);
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-10-21 22:01:08 +00:00
|
|
|
INSIST(isc_memctx_create(0, 0, &mctx) == ISC_R_SUCCESS);
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-10-22 01:33:20 +00:00
|
|
|
INSIST(isc_taskmgr_create(mctx, workers, 0, &manager) ==
|
|
|
|
ISC_R_SUCCESS);
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-10-22 01:33:20 +00:00
|
|
|
INSIST(isc_task_create(manager, my_shutdown, "1", 0, &t1) ==
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
INSIST(isc_task_create(manager, my_shutdown, "2", 0, &t2) ==
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
INSIST(isc_task_create(manager, my_shutdown, "3", 0, &t3) ==
|
|
|
|
ISC_R_SUCCESS);
|
|
|
|
INSIST(isc_task_create(manager, my_shutdown, "4", 0, &t4) ==
|
|
|
|
ISC_R_SUCCESS);
|
1998-08-18 08:05:45 +00:00
|
|
|
|
1998-10-16 01:18:31 +00:00
|
|
|
timgr = NULL;
|
1998-10-21 01:57:35 +00:00
|
|
|
INSIST(isc_timermgr_create(mctx, &timgr) == ISC_R_SUCCESS);
|
1998-10-16 01:18:31 +00:00
|
|
|
ti1 = NULL;
|
1998-10-23 23:00:40 +00:00
|
|
|
isc_time_settoepoch(&absolute);
|
|
|
|
isc_interval_set(&interval, 1, 0);
|
1998-10-21 01:57:35 +00:00
|
|
|
INSIST(isc_timer_create(timgr, isc_timertype_ticker,
|
1998-10-22 01:33:20 +00:00
|
|
|
&absolute, &interval,
|
1998-10-21 01:57:35 +00:00
|
|
|
t1, my_tick, "foo", &ti1) == ISC_R_SUCCESS);
|
1998-10-16 01:18:31 +00:00
|
|
|
ti2 = NULL;
|
1998-10-23 23:00:40 +00:00
|
|
|
isc_time_settoepoch(&absolute);
|
|
|
|
isc_interval_set(&interval, 1, 0);
|
1998-10-21 01:57:35 +00:00
|
|
|
INSIST(isc_timer_create(timgr, isc_timertype_ticker,
|
1998-10-22 01:33:20 +00:00
|
|
|
&absolute, &interval,
|
1998-10-21 01:57:35 +00:00
|
|
|
t2, my_tick, "bar", &ti2) == ISC_R_SUCCESS);
|
1998-10-16 01:18:31 +00:00
|
|
|
|
1998-08-18 19:28:30 +00:00
|
|
|
printf("task 1 = %p\n", t1);
|
|
|
|
printf("task 2 = %p\n", t2);
|
|
|
|
sleep(2);
|
|
|
|
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "1",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t1, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "2",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t2, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "3",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t3, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "4",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t4, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "2",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t2, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "3",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t3, &event);
|
1998-10-22 01:59:50 +00:00
|
|
|
event = isc_event_allocate(mctx, (void *)main, 1, my_callback, "4",
|
1998-10-21 02:26:57 +00:00
|
|
|
sizeof *event);
|
|
|
|
isc_task_send(t4, &event);
|
|
|
|
isc_task_purge(t3, NULL, 0);
|
|
|
|
|
|
|
|
isc_task_detach(&t1);
|
|
|
|
isc_task_detach(&t2);
|
|
|
|
isc_task_detach(&t3);
|
|
|
|
isc_task_detach(&t4);
|
1998-08-18 08:05:45 +00:00
|
|
|
|
1998-10-16 20:20:31 +00:00
|
|
|
sleep(10);
|
1998-08-17 23:15:50 +00:00
|
|
|
printf("destroy\n");
|
1998-10-21 01:57:35 +00:00
|
|
|
isc_timer_detach(&ti1);
|
|
|
|
isc_timer_detach(&ti2);
|
|
|
|
isc_timermgr_destroy(&timgr);
|
1998-10-21 02:26:57 +00:00
|
|
|
isc_taskmgr_destroy(&manager);
|
1998-08-17 23:15:50 +00:00
|
|
|
printf("destroyed\n");
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-10-21 22:01:08 +00:00
|
|
|
isc_mem_stats(mctx, stdout);
|
|
|
|
isc_memctx_destroy(&mctx);
|
1998-08-17 22:05:58 +00:00
|
|
|
}
|