--- libaitsched/src/aitsched.c 2012/01/08 00:51:17 1.4 +++ libaitsched/src/aitsched.c 2012/01/08 02:01:41 1.4.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitsched.c,v 1.4 2012/01/08 00:51:17 misho Exp $ +* $Id: aitsched.c,v 1.4.2.1 2012/01/08 02:01:41 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -122,12 +122,30 @@ schedInit(void ** __restrict data, size_t datlen) { sched_root_task_t *root = NULL; int (*func)(sched_root_task_t *); +#ifdef HAVE_LIBPTHREAD + register int i; +#endif root = malloc(sizeof(sched_root_task_t)); if (!root) { LOGERR; } else { memset(root, 0, sizeof(sched_root_task_t)); + +#ifdef HAVE_LIBPTHREAD + for (i = 0; i < taskMAX; i++) + if (pthread_mutex_init(&root->root_mtx[i], NULL)) { + LOGERR; + while (i) + pthread_mutex_destroy(&root->root_mtx[--i]); + free(root); + return NULL; + } + + for (i = 0; i < taskMAX; i++) + ROOT_QLOCK(root, i); +#endif + TAILQ_INIT(&root->root_read); TAILQ_INIT(&root->root_write); TAILQ_INIT(&root->root_timer); @@ -136,6 +154,11 @@ schedInit(void ** __restrict data, size_t datlen) TAILQ_INIT(&root->root_ready); TAILQ_INIT(&root->root_unuse); +#ifdef HAVE_LIBPTHREAD + for (i = 0; i < taskMAX; i++) + ROOT_QUNLOCK(root, i); +#endif + if (data && *data) { if (datlen) { root->root_data.iov_base = *data; @@ -163,10 +186,17 @@ int schedEnd(sched_root_task_t ** __restrict root) { sched_task_t *task; +#ifdef HAVE_LIBPTHREAD + register int i; +#endif if (!root || !*root) return -1; +#ifdef HAVE_LIBPTHREAD + for (i = 0; i < taskMAX; i++) + ROOT_QLOCK(*root, i); +#endif TAILQ_FOREACH(task, &(*root)->root_read, task_node) { schedCancel(task); } @@ -187,9 +217,18 @@ schedEnd(sched_root_task_t ** __restrict root) TAILQ_REMOVE(&(*root)->root_unuse, task, task_node); free(task); } +#ifdef HAVE_LIBPTHREAD + for (i = 0; i < taskMAX; i++) + ROOT_QUNLOCK(*root, i); +#endif if ((*root)->root_hooks.hook_root.fini) (*root)->root_hooks.hook_root.fini(*root, NULL); + +#ifdef HAVE_LIBPTHREAD + for (i = 0; i < taskMAX; i++) + pthread_mutex_destroy(&(*root)->root_mtx[i]); +#endif free(*root); *root = NULL;