|
version 1.11, 2012/08/02 13:56:19
|
version 1.18.4.4, 2013/08/15 18:39:00
|
|
Line 12 terms:
|
Line 12 terms:
|
| All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
|
| Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 | Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
|
| Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
|
Line 110 sched_hook_cancel(void *task, void *arg __unused)
|
Line 110 sched_hook_cancel(void *task, void *arg __unused)
|
| #ifdef AIO_SUPPORT |
#ifdef AIO_SUPPORT |
| struct aiocb *acb; |
struct aiocb *acb; |
| #ifdef EVFILT_LIO |
#ifdef EVFILT_LIO |
| |
register int i = 0; |
| struct aiocb **acbs; |
struct aiocb **acbs; |
| register int i; |
|
| #endif /* EVFILT_LIO */ |
#endif /* EVFILT_LIO */ |
| #endif /* AIO_SUPPORT */ |
#endif /* AIO_SUPPORT */ |
| |
|
|
Line 162 sched_hook_cancel(void *task, void *arg __unused)
|
Line 162 sched_hook_cancel(void *task, void *arg __unused)
|
| #else |
#else |
| EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_DELETE, 0, 0, (void*) TASK_VAL(t)); |
EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_DELETE, 0, 0, (void*) TASK_VAL(t)); |
| #endif |
#endif |
| |
/* restore signal */ |
| |
signal(TASK_VAL(t), SIG_DFL); |
| break; |
break; |
| #ifdef AIO_SUPPORT |
#ifdef AIO_SUPPORT |
| case taskAIO: |
case taskAIO: |
|
Line 207 sched_hook_cancel(void *task, void *arg __unused)
|
Line 209 sched_hook_cancel(void *task, void *arg __unused)
|
| #endif |
#endif |
| break; |
break; |
| #endif |
#endif |
| |
case taskTHREAD: |
| |
#ifdef HAVE_LIBPTHREAD |
| |
pthread_cancel((pthread_t) TASK_VAL(t)); |
| |
#endif |
| |
return NULL; |
| |
case taskRTC: |
| |
timer_delete((timer_t) TASK_FLAG(t)); |
| |
schedCancel((sched_task_t*) TASK_RET(t)); |
| |
return NULL; |
| default: |
default: |
| return NULL; |
return NULL; |
| } |
} |
|
Line 215 sched_hook_cancel(void *task, void *arg __unused)
|
Line 226 sched_hook_cancel(void *task, void *arg __unused)
|
| return NULL; |
return NULL; |
| } |
} |
| |
|
| |
#ifdef HAVE_LIBPTHREAD |
| /* |
/* |
| |
* sched_hook_thread() - Default THREAD hook |
| |
* |
| |
* @task = current task |
| |
* @arg = pthread attributes |
| |
* return: <0 errors and 0 ok |
| |
*/ |
| |
void * |
| |
sched_hook_thread(void *task, void *arg) |
| |
{ |
| |
sched_task_t *t = task; |
| |
pthread_t tid; |
| |
sigset_t s, o; |
| |
|
| |
if (!t || !TASK_ROOT(t)) |
| |
return (void*) -1; |
| |
|
| |
sigfillset(&s); |
| |
pthread_sigmask(SIG_BLOCK, &s, &o); |
| |
if ((errno = pthread_create(&tid, (pthread_attr_t*) arg, |
| |
(void *(*)(void*)) _sched_threadWrapper, t))) { |
| |
LOGERR; |
| |
pthread_sigmask(SIG_SETMASK, &o, NULL); |
| |
return (void*) -1; |
| |
} else |
| |
TASK_VAL(t) = (u_long) tid; |
| |
|
| |
if (!TASK_ISLOCKED(t)) |
| |
TASK_LOCK(t); |
| |
|
| |
pthread_sigmask(SIG_SETMASK, &o, NULL); |
| |
return NULL; |
| |
} |
| |
#endif |
| |
|
| |
/* |
| * sched_hook_read() - Default READ hook |
* sched_hook_read() - Default READ hook |
| * |
* |
| * @task = current task |
* @task = current task |
|
Line 299 sched_hook_alarm(void *task, void *arg __unused)
|
Line 346 sched_hook_alarm(void *task, void *arg __unused)
|
| return (void*) -1; |
return (void*) -1; |
| |
|
| #ifdef __NetBSD__ |
#ifdef __NetBSD__ |
| EV_SET(&chg[0], (uintptr_t) TASK_DATA(t), EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, | EV_SET(&chg[0], (uintptr_t) TASK_DATA(t), EVFILT_TIMER, EV_ADD | EV_CLEAR, 0, |
| t->task_val.ts.tv_sec * 1000 + t->task_val.ts.tv_nsec / 1000000, |
t->task_val.ts.tv_sec * 1000 + t->task_val.ts.tv_nsec / 1000000, |
| (intptr_t) TASK_DATA(t)); |
(intptr_t) TASK_DATA(t)); |
| #else |
#else |
| EV_SET(&chg[0], (uintptr_t) TASK_DATA(t), EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, | EV_SET(&chg[0], (uintptr_t) TASK_DATA(t), EVFILT_TIMER, EV_ADD | EV_CLEAR, 0, |
| t->task_val.ts.tv_sec * 1000 + t->task_val.ts.tv_nsec / 1000000, |
t->task_val.ts.tv_sec * 1000 + t->task_val.ts.tv_nsec / 1000000, |
| (void*) TASK_DATA(t)); |
(void*) TASK_DATA(t)); |
| #endif |
#endif |
|
Line 407 sched_hook_signal(void *task, void *arg __unused)
|
Line 454 sched_hook_signal(void *task, void *arg __unused)
|
| if (!t || !TASK_ROOT(t)) |
if (!t || !TASK_ROOT(t)) |
| return (void*) -1; |
return (void*) -1; |
| |
|
| |
/* ignore signal */ |
| |
signal(TASK_VAL(t), SIG_IGN); |
| |
|
| #ifdef __NetBSD__ |
#ifdef __NetBSD__ |
| EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_ADD, 0, 0, (intptr_t) TASK_VAL(t)); | EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_ADD | EV_CLEAR, 0, 0, (intptr_t) TASK_VAL(t)); |
| #else |
#else |
| EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_ADD, 0, 0, (void*) TASK_VAL(t)); | EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_ADD | EV_CLEAR, 0, 0, (void*) TASK_VAL(t)); |
| #endif |
#endif |
| if (kevent(TASK_ROOT(t)->root_kq, chg, 1, NULL, 0, &timeout) == -1) { |
if (kevent(TASK_ROOT(t)->root_kq, chg, 1, NULL, 0, &timeout) == -1) { |
| if (TASK_ROOT(t)->root_hooks.hook_exec.exception) |
if (TASK_ROOT(t)->root_hooks.hook_exec.exception) |
|
Line 550 sched_hook_fetch(void *root, void *arg __unused)
|
Line 600 sched_hook_fetch(void *root, void *arg __unused)
|
| sched_timespecinf(&r->root_wait); |
sched_timespecinf(&r->root_wait); |
| } |
} |
| #else |
#else |
| if (!TAILQ_FIRST(&r->root_eventlo) && (task = TAILQ_FIRST(&r->root_timer))) { | if (!TAILQ_FIRST(&r->root_task) && (task = TAILQ_FIRST(&r->root_timer))) { |
| clock_gettime(CLOCK_MONOTONIC, &now); |
clock_gettime(CLOCK_MONOTONIC, &now); |
| |
|
| m = TASK_TS(task); |
m = TASK_TS(task); |
|
Line 561 sched_hook_fetch(void *root, void *arg __unused)
|
Line 611 sched_hook_fetch(void *root, void *arg __unused)
|
| sched_timespecinf(&r->root_wait); |
sched_timespecinf(&r->root_wait); |
| } |
} |
| #endif |
#endif |
| /* if present member of eventLo, set NOWAIT */ | /* if present member of task, set NOWAIT */ |
| if (TAILQ_FIRST(&r->root_eventlo)) | if (TAILQ_FIRST(&r->root_task)) |
| sched_timespecclear(&r->root_wait); |
sched_timespecclear(&r->root_wait); |
| |
|
| if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) |
if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) |
|
Line 592 sched_hook_fetch(void *root, void *arg __unused)
|
Line 642 sched_hook_fetch(void *root, void *arg __unused)
|
| TAILQ_FOREACH_SAFE(task, &r->root_read, task_node, tmp) { |
TAILQ_FOREACH_SAFE(task, &r->root_read, task_node, tmp) { |
| if (TASK_FD(task) != ((intptr_t) res[i].udata)) |
if (TASK_FD(task) != ((intptr_t) res[i].udata)) |
| continue; |
continue; |
| else | else { |
| flg++; |
flg++; |
| |
TASK_RET(task) = res[i].data; |
| |
TASK_FLAG(task) = (u_long) res[i].fflags; |
| |
} |
| /* remove read handle */ |
/* remove read handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_lock(&r->root_mtx[taskREAD]); |
pthread_mutex_lock(&r->root_mtx[taskREAD]); |
|
Line 642 sched_hook_fetch(void *root, void *arg __unused)
|
Line 695 sched_hook_fetch(void *root, void *arg __unused)
|
| TAILQ_FOREACH_SAFE(task, &r->root_write, task_node, tmp) { |
TAILQ_FOREACH_SAFE(task, &r->root_write, task_node, tmp) { |
| if (TASK_FD(task) != ((intptr_t) res[i].udata)) |
if (TASK_FD(task) != ((intptr_t) res[i].udata)) |
| continue; |
continue; |
| else | else { |
| flg++; |
flg++; |
| |
TASK_RET(task) = res[i].data; |
| |
TASK_FLAG(task) = (u_long) res[i].fflags; |
| |
} |
| /* remove write handle */ |
/* remove write handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_lock(&r->root_mtx[taskWRITE]); |
pthread_mutex_lock(&r->root_mtx[taskWRITE]); |
|
Line 692 sched_hook_fetch(void *root, void *arg __unused)
|
Line 748 sched_hook_fetch(void *root, void *arg __unused)
|
| TAILQ_FOREACH_SAFE(task, &r->root_alarm, task_node, tmp) { |
TAILQ_FOREACH_SAFE(task, &r->root_alarm, task_node, tmp) { |
| if ((uintptr_t) TASK_DATA(task) != ((uintptr_t) res[i].udata)) |
if ((uintptr_t) TASK_DATA(task) != ((uintptr_t) res[i].udata)) |
| continue; |
continue; |
| else | else { |
| flg++; |
flg++; |
| |
TASK_RET(task) = res[i].data; |
| |
TASK_FLAG(task) = (u_long) res[i].fflags; |
| |
} |
| /* remove alarm handle */ |
/* remove alarm handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_lock(&r->root_mtx[taskALARM]); |
pthread_mutex_lock(&r->root_mtx[taskALARM]); |
|
Line 722 sched_hook_fetch(void *root, void *arg __unused)
|
Line 781 sched_hook_fetch(void *root, void *arg __unused)
|
| continue; |
continue; |
| else { |
else { |
| flg++; |
flg++; |
| TASK_DATA(task) = (void*) (uintptr_t) res[i].data; | TASK_RET(task) = res[i].data; |
| TASK_DATLEN(task) = res[i].fflags; | TASK_FLAG(task) = (u_long) res[i].fflags; |
| } |
} |
| /* remove node handle */ |
/* remove node handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
|
Line 753 sched_hook_fetch(void *root, void *arg __unused)
|
Line 812 sched_hook_fetch(void *root, void *arg __unused)
|
| continue; |
continue; |
| else { |
else { |
| flg++; |
flg++; |
| TASK_DATA(task) = (void*) (uintptr_t) res[i].data; | TASK_RET(task) = res[i].data; |
| TASK_DATLEN(task) = res[i].fflags; | TASK_FLAG(task) = (u_long) res[i].fflags; |
| } |
} |
| /* remove proc handle */ |
/* remove proc handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
|
Line 782 sched_hook_fetch(void *root, void *arg __unused)
|
Line 841 sched_hook_fetch(void *root, void *arg __unused)
|
| TAILQ_FOREACH_SAFE(task, &r->root_signal, task_node, tmp) { |
TAILQ_FOREACH_SAFE(task, &r->root_signal, task_node, tmp) { |
| if (TASK_VAL(task) != ((uintptr_t) res[i].udata)) |
if (TASK_VAL(task) != ((uintptr_t) res[i].udata)) |
| continue; |
continue; |
| else | else { |
| flg++; |
flg++; |
| |
TASK_RET(task) = res[i].data; |
| |
TASK_FLAG(task) = (u_long) res[i].fflags; |
| |
} |
| /* remove signal handle */ |
/* remove signal handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_lock(&r->root_mtx[taskSIGNAL]); |
pthread_mutex_lock(&r->root_mtx[taskSIGNAL]); |
|
Line 812 sched_hook_fetch(void *root, void *arg __unused)
|
Line 874 sched_hook_fetch(void *root, void *arg __unused)
|
| acb = (struct aiocb*) TASK_VAL(task); |
acb = (struct aiocb*) TASK_VAL(task); |
| if (acb != ((struct aiocb*) res[i].udata)) |
if (acb != ((struct aiocb*) res[i].udata)) |
| continue; |
continue; |
| else | else { |
| flg++; |
flg++; |
| |
TASK_RET(task) = res[i].data; |
| |
TASK_FLAG(task) = (u_long) res[i].fflags; |
| |
} |
| /* remove user handle */ |
/* remove user handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_lock(&r->root_mtx[taskAIO]); |
pthread_mutex_lock(&r->root_mtx[taskAIO]); |
|
Line 851 sched_hook_fetch(void *root, void *arg __unused)
|
Line 916 sched_hook_fetch(void *root, void *arg __unused)
|
| acbs = (struct aiocb**) TASK_VAL(task); |
acbs = (struct aiocb**) TASK_VAL(task); |
| if (acbs != ((struct aiocb**) res[i].udata)) |
if (acbs != ((struct aiocb**) res[i].udata)) |
| continue; |
continue; |
| else | else { |
| flg++; |
flg++; |
| |
TASK_RET(task) = res[i].data; |
| |
TASK_FLAG(task) = (u_long) res[i].fflags; |
| |
} |
| /* remove user handle */ |
/* remove user handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_lock(&r->root_mtx[taskLIO]); |
pthread_mutex_lock(&r->root_mtx[taskLIO]); |
|
Line 900 sched_hook_fetch(void *root, void *arg __unused)
|
Line 968 sched_hook_fetch(void *root, void *arg __unused)
|
| continue; |
continue; |
| else { |
else { |
| flg++; |
flg++; |
| TASK_DATA(task) = (void*) res[i].data; | TASK_RET(task) = res[i].data; |
| TASK_DATLEN(task) = res[i].fflags; | TASK_FLAG(task) = (u_long) res[i].fflags; |
| } |
} |
| /* remove user handle */ |
/* remove user handle */ |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
|
Line 957 sched_hook_fetch(void *root, void *arg __unused)
|
Line 1025 sched_hook_fetch(void *root, void *arg __unused)
|
| #endif |
#endif |
| } |
} |
| |
|
| /* put eventlo priority task to ready queue, if there is no ready task or | /* put regular task priority task to ready queue, |
| reach max missed fetch-rotate */ | if there is no ready task or reach max missing hit for regular task */ |
| if ((task = TAILQ_FIRST(&r->root_eventlo))) { | if ((task = TAILQ_FIRST(&r->root_task))) { |
| if (!TAILQ_FIRST(&r->root_ready) || r->root_eventlo_miss > MAX_EVENTLO_MISS) { | if (!TAILQ_FIRST(&r->root_ready) || r->root_miss >= TASK_VAL(task)) { |
| r->root_eventlo_miss = 0; | r->root_miss ^= r->root_miss; |
| |
|
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_lock(&r->root_mtx[taskEVENTLO]); | pthread_mutex_lock(&r->root_mtx[taskTASK]); |
| #endif |
#endif |
| TAILQ_REMOVE(&r->root_eventlo, task, task_node); | TAILQ_REMOVE(&r->root_task, task, task_node); |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
| pthread_mutex_unlock(&r->root_mtx[taskEVENTLO]); | pthread_mutex_unlock(&r->root_mtx[taskTASK]); |
| #endif |
#endif |
| task->task_type = taskREADY; |
task->task_type = taskREADY; |
| #ifdef HAVE_LIBPTHREAD |
#ifdef HAVE_LIBPTHREAD |
|
Line 979 sched_hook_fetch(void *root, void *arg __unused)
|
Line 1047 sched_hook_fetch(void *root, void *arg __unused)
|
| pthread_mutex_unlock(&r->root_mtx[taskREADY]); |
pthread_mutex_unlock(&r->root_mtx[taskREADY]); |
| #endif |
#endif |
| } else |
} else |
| r->root_eventlo_miss++; | r->root_miss++; |
| } else |
} else |
| r->root_eventlo_miss = 0; | r->root_miss ^= r->root_miss; |
| |
|
| /* OK, lets get ready task !!! */ |
/* OK, lets get ready task !!! */ |
| task = TAILQ_FIRST(&r->root_ready); |
task = TAILQ_FIRST(&r->root_ready); |
|
Line 1053 sched_hook_condition(void *root, void *arg)
|
Line 1121 sched_hook_condition(void *root, void *arg)
|
| return NULL; |
return NULL; |
| |
|
| return (void*) (r->root_cond - *(intptr_t*) arg); |
return (void*) (r->root_cond - *(intptr_t*) arg); |
| |
} |
| |
|
| |
/* |
| |
* sched_hook_rtc() - Default RTC hook |
| |
* |
| |
* @task = current task |
| |
* @arg = unused |
| |
* return: <0 errors and 0 ok |
| |
*/ |
| |
void * |
| |
sched_hook_rtc(void *task, void *arg __unused) |
| |
{ |
| |
sched_task_t *sigt = NULL, *t = task; |
| |
struct itimerspec its; |
| |
struct sigevent evt; |
| |
timer_t tmr; |
| |
|
| |
if (!t || !TASK_ROOT(t)) |
| |
return (void*) -1; |
| |
|
| |
memset(&evt, 0, sizeof evt); |
| |
evt.sigev_notify = SIGEV_SIGNAL; |
| |
evt.sigev_signo = TASK_DATLEN(t) + SIGRTMIN; |
| |
evt.sigev_value.sival_ptr = TASK_DATA(t); |
| |
|
| |
if (timer_create(CLOCK_MONOTONIC, &evt, &tmr) == -1) { |
| |
if (TASK_ROOT(t)->root_hooks.hook_exec.exception) |
| |
TASK_ROOT(t)->root_hooks.hook_exec.exception(TASK_ROOT(t), NULL); |
| |
else |
| |
LOGERR; |
| |
return (void*) -1; |
| |
} else |
| |
TASK_FLAG(t) = (u_long) tmr; |
| |
|
| |
if (!(sigt = schedSignal(TASK_ROOT(t), TASK_FUNC(t), TASK_ARG(t), evt.sigev_signo, |
| |
TASK_DATA(t), (size_t) tmr))) { |
| |
if (TASK_ROOT(t)->root_hooks.hook_exec.exception) |
| |
TASK_ROOT(t)->root_hooks.hook_exec.exception(TASK_ROOT(t), NULL); |
| |
else |
| |
LOGERR; |
| |
timer_delete(tmr); |
| |
return (void*) -1; |
| |
} else |
| |
TASK_RET(t) = (uintptr_t) sigt; |
| |
|
| |
memset(&its, 0, sizeof its); |
| |
its.it_value.tv_sec = t->task_val.ts.tv_sec; |
| |
its.it_value.tv_nsec = t->task_val.ts.tv_nsec; |
| |
|
| |
if (timer_settime(tmr, TIMER_ABSTIME, &its, NULL) == -1) { |
| |
if (TASK_ROOT(t)->root_hooks.hook_exec.exception) |
| |
TASK_ROOT(t)->root_hooks.hook_exec.exception(TASK_ROOT(t), NULL); |
| |
else |
| |
LOGERR; |
| |
schedCancel(sigt); |
| |
timer_delete(tmr); |
| |
return (void*) -1; |
| |
} |
| |
|
| |
return NULL; |
| } |
} |