File:  [ELWIX - Embedded LightWeight unIX -] / libaitsched / example / test_time.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Mon May 14 12:09:12 2012 UTC (12 years, 1 month ago) by misho
Branches: MAIN
CVS tags: sched2_1, sched1_6, SCHED2_0, SCHED1_5, HEAD
version 1.5

    1: #include <stdio.h>
    2: #include <unistd.h>
    3: #include <fcntl.h>
    4: #include <sys/types.h>
    5: #include <sys/stat.h>
    6: #include <sys/signal.h>
    7: #include <netinet/in.h>
    8: #include <aitsched.h>
    9: 
   10: intptr_t Kill;
   11: 
   12: void *event(sched_task_t *arg)
   13: {
   14: 	printf("Event::\n");
   15: 	return NULL;
   16: }
   17: 
   18: void *eventlo(sched_task_t *arg)
   19: {
   20: 	printf("EventLOW::\n");
   21: 	return NULL;
   22: }
   23: 
   24: void *timer(sched_task_t *arg)
   25: {
   26: 	printf("Timer %ld sec::\n", (intptr_t) TASK_ARG(arg));
   27: 	return NULL;
   28: }
   29: 
   30: void *once(sched_task_t *arg)
   31: {
   32: 	printf("once::\n");
   33: 	return NULL;
   34: }
   35: 
   36: void sig(int s)
   37: {
   38: 	switch (s) {
   39: 		case SIGTERM:
   40: 			Kill++;
   41: 			break;
   42: 	}
   43: }
   44: 
   45: int
   46: main(int argc, char **argv)
   47: {
   48: 	sched_root_task_t *root;
   49: 	struct timespec ts = { 20, 0 };
   50: //	struct timespec p = { 0, 10000000 };
   51: 
   52: 	signal(SIGTERM, sig);
   53: 
   54: 	root = schedBegin();
   55: 	if (!root) {
   56: 		printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
   57: 		return 1;
   58: 	}
   59: 
   60: 	if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
   61: 		printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
   62: 		return 4;
   63: 	} else
   64: 		ts.tv_sec = 15;
   65: 	if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
   66: 		printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
   67: 		return 4;
   68: 	} else
   69: 		ts.tv_sec = 10;
   70: 
   71: 	if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
   72: 		printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
   73: 		return 2;
   74: 	}
   75: 
   76: 	if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
   77: 		printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
   78: 		return 3;
   79: 	}
   80: 
   81: 	if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
   82: 		printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
   83: 		return 4;
   84: 	}
   85: 
   86: 	schedCallOnce(root, once, "000000", 42, NULL, 0);
   87: 
   88: 	printf("read_queue=%d timer_queue=%d\n", 
   89: 			ROOT_QUEUE_EMPTY(root, read), ROOT_QUEUE_EMPTY(root, timer));
   90: 
   91: //	schedPolling(root, &p, NULL);
   92: 	schedRun(root, &Kill);
   93: 	schedEnd(&root);
   94: 	return 0;
   95: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>