1998-08-17 22:05:58 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "memcluster.h"
|
|
|
|
#include "task.h"
|
|
|
|
|
1998-08-17 23:15:50 +00:00
|
|
|
/*ARGSUSED*/
|
1998-08-17 22:05:58 +00:00
|
|
|
boolean_t
|
1998-08-17 23:15:50 +00:00
|
|
|
my_callback(task_t task, void *arg, generic_event_t event) {
|
|
|
|
int i, j;
|
|
|
|
char *name = arg;
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-08-17 23:15:50 +00:00
|
|
|
j = 0;
|
|
|
|
for (i = 0; i < 100000000; i++)
|
|
|
|
j += 100;
|
|
|
|
printf("task %s: %d\n", name, j);
|
|
|
|
|
1998-08-17 22:05:58 +00:00
|
|
|
return (FALSE);
|
|
|
|
}
|
|
|
|
|
1998-08-17 23:15:50 +00:00
|
|
|
/*ARGSUSED*/
|
1998-08-17 22:05:58 +00:00
|
|
|
boolean_t
|
1998-08-17 23:15:50 +00:00
|
|
|
my_shutdown(task_t task, void *arg, generic_event_t event) {
|
|
|
|
char *name = arg;
|
|
|
|
|
|
|
|
printf("shutdown %s\n", name);
|
1998-08-17 22:05:58 +00:00
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
generic_event_t
|
|
|
|
event_allocate(mem_context_t mctx, event_type_t type, event_action_t action,
|
|
|
|
size_t size) {
|
|
|
|
generic_event_t event;
|
|
|
|
|
|
|
|
if (size < sizeof *event)
|
|
|
|
return (NULL);
|
|
|
|
event = mem_get(mctx, size);
|
|
|
|
if (event == NULL)
|
|
|
|
return (NULL);
|
|
|
|
event->mctx = mctx;
|
1998-08-17 23:15:50 +00:00
|
|
|
event->size = size;
|
1998-08-17 22:05:58 +00:00
|
|
|
event->type = type;
|
|
|
|
event->action = action;
|
|
|
|
|
|
|
|
return (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-08-17 23:15:50 +00:00
|
|
|
main(int argc, char *argv[]) {
|
1998-08-17 22:05:58 +00:00
|
|
|
mem_context_t mctx = NULL;
|
|
|
|
task_manager_t manager = NULL;
|
1998-08-17 23:15:50 +00:00
|
|
|
task_t t1 = NULL, t2 = NULL;
|
1998-08-17 22:05:58 +00:00
|
|
|
generic_event_t event;
|
1998-08-17 23:15:50 +00:00
|
|
|
unsigned int workers;
|
|
|
|
|
|
|
|
if (argc > 1)
|
|
|
|
workers = atoi(argv[1]);
|
|
|
|
else
|
|
|
|
workers = 2;
|
|
|
|
printf("%d workers\n", workers);
|
1998-08-17 22:05:58 +00:00
|
|
|
|
|
|
|
INSIST(mem_context_create(0, 0, &mctx) == 0);
|
|
|
|
|
1998-08-17 23:15:50 +00:00
|
|
|
INSIST(task_manager_create(mctx, workers, 0, &manager) == workers);
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-08-17 23:15:50 +00:00
|
|
|
INSIST(task_allocate(manager, "1", my_shutdown, 0, &t1));
|
|
|
|
INSIST(task_allocate(manager, "2", my_shutdown, 0, &t2));
|
1998-08-17 22:05:58 +00:00
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
1998-08-17 23:15:50 +00:00
|
|
|
task_send_event(t1, event);
|
1998-08-17 22:05:58 +00:00
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
1998-08-17 23:15:50 +00:00
|
|
|
task_send_event(t2, event);
|
1998-08-17 22:05:58 +00:00
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
1998-08-17 23:15:50 +00:00
|
|
|
task_send_event(t1, event);
|
1998-08-17 22:05:58 +00:00
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
1998-08-17 23:15:50 +00:00
|
|
|
task_send_event(t2, event);
|
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
|
|
|
task_send_event(t1, event);
|
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
|
|
|
task_send_event(t2, event);
|
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
|
|
|
task_send_event(t1, event);
|
|
|
|
event = event_allocate(mctx, 1, my_callback, sizeof *event);
|
|
|
|
task_send_event(t2, event);
|
1998-08-17 22:05:58 +00:00
|
|
|
|
1998-08-17 23:15:50 +00:00
|
|
|
task_shutdown(t1);
|
|
|
|
task_shutdown(t2);
|
|
|
|
task_detach(&t1);
|
|
|
|
task_detach(&t2);
|
|
|
|
printf("destroy\n");
|
1998-08-17 22:05:58 +00:00
|
|
|
task_manager_destroy(&manager);
|
1998-08-17 23:15:50 +00:00
|
|
|
printf("destroyed\n");
|
1998-08-17 22:05:58 +00:00
|
|
|
|
|
|
|
mem_stats(mctx, stdout);
|
|
|
|
}
|