Annotation of libaitsched/example/test_time.c, revision 1.2.4.2

1.2       misho       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: 
1.2.4.1   misho      30: void *alarmz(sched_task_t *arg)
                     31: {
                     32:        printf("Alarm %ld sec::\n", (intptr_t) TASK_ARG(arg));
                     33:        return NULL;
                     34: }
                     35: 
1.2       misho      36: void *once(sched_task_t *arg)
                     37: {
                     38:        printf("once::\n");
                     39:        return NULL;
                     40: }
                     41: 
                     42: void sig(int s)
                     43: {
                     44:        switch (s) {
                     45:                case SIGTERM:
                     46:                        Kill++;
                     47:                        break;
                     48:        }
                     49: }
                     50: 
                     51: int
                     52: main(int argc, char **argv)
                     53: {
                     54:        sched_root_task_t *root;
                     55:        struct timespec ts = { 20, 0 };
                     56: //     struct timespec p = { 0, 10000000 };
                     57: 
                     58:        signal(SIGTERM, sig);
                     59: 
                     60:        root = schedBegin();
                     61:        if (!root) {
                     62:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     63:                return 1;
                     64:        }
                     65: 
                     66:        if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
                     67:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     68:                return 4;
                     69:        } else
                     70:                ts.tv_sec = 15;
                     71:        if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
                     72:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     73:                return 4;
                     74:        } else
                     75:                ts.tv_sec = 10;
                     76: 
                     77:        if (!schedEvent(root, event, "piuk", 1234, NULL, 0)) {
                     78:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     79:                return 2;
                     80:        }
                     81: 
                     82:        if (!schedEventLo(root, eventlo, "piuk", 1111, NULL, 0)) {
                     83:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     84:                return 3;
                     85:        }
                     86: 
                     87:        if (!schedTimer(root, timer, (void*) ts.tv_sec, ts, NULL, 0)) {
                     88:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     89:                return 4;
                     90:        }
                     91: 
1.2.4.1   misho      92:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, NULL, 0)) {
                     93:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
                     94:                return 5;
1.2.4.2 ! misho      95:        } else {
        !            96:                ts.tv_sec = 3;
        !            97:                ts.tv_nsec = 500000000;
        !            98:        }
        !            99: 
        !           100:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 1, 0)) {
        !           101:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
        !           102:                return 5;
        !           103:        }
        !           104:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 2, 0)) {
        !           105:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
        !           106:                return 5;
        !           107:        } else {
        !           108:                ts.tv_sec = 0;
        !           109:                ts.tv_nsec = 700000000;
        !           110:        }
        !           111:        if (!schedAlarm(root, alarmz, (void*) ts.tv_sec, ts, (void*) 3, 0)) {
        !           112:                printf("Error:: #%d - %s\n", sched_GetErrno(), sched_GetError());
        !           113:                return 5;
1.2.4.1   misho     114:        }
                    115: 
1.2       misho     116:        schedCallOnce(root, once, "000000", 42, NULL, 0);
                    117: 
                    118:        printf("read_queue=%d timer_queue=%d\n", 
                    119:                        ROOT_QUEUE_EMPTY(root, read), ROOT_QUEUE_EMPTY(root, timer));
                    120: 
                    121: //     schedPolling(root, &p, NULL);
                    122:        schedRun(root, &Kill);
                    123:        schedEnd(&root);
                    124:        return 0;
                    125: }

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