Diff for /libaitsched/src/tasks.c between versions 1.8 and 1.8.2.1

version 1.8, 2012/05/30 08:52:45 version 1.8.2.1, 2012/05/31 14:17:59
Line 212  schedWrite(sched_root_task_t * __restrict root, sched_ Line 212  schedWrite(sched_root_task_t * __restrict root, sched_
 }  }
   
 /*  /*
    * schedNode() - Add NODE task to scheduler queue
    *
    * @root = root task
    * @func = task execution function
    * @arg = 1st func argument
    * @fd = fd handle
    * @opt_data = Optional data
    * @opt_dlen = Optional data length
    * return: NULL error or !=NULL new queued task
    */
   sched_task_t *
   schedNode(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, int fd, 
                   void *opt_data, size_t opt_dlen)
   {
           sched_task_t *task;
           void *ptr;
   
           if (!root || !func)
                   return NULL;
   
           /* get new task */
           if (!(task = _sched_useTask(root)))
                   return NULL;
   
           memset(task, 0, sizeof(sched_task_t));
           task->task_id = 0;
           task->task_lock = 0;
           task->task_func = func;
           TASK_TYPE(task) = taskNODE;
           TASK_ROOT(task) = root;
   
           TASK_ARG(task) = arg;
           TASK_FD(task) = fd;
   
           TASK_DATA(task) = opt_data;
           TASK_DATLEN(task) = opt_dlen;
   
           if (root->root_hooks.hook_add.node)
                   ptr = root->root_hooks.hook_add.node(task, NULL);
           else
                   ptr = NULL;
   
           if (!ptr) {
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_lock(&root->root_mtx[taskNODE]);
   #endif
                   TAILQ_INSERT_TAIL(&root->root_node, task, task_node);
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_unlock(&root->root_mtx[taskNODE]);
   #endif
           } else
                   task = _sched_unuseTask(task);
   
           return task;
   }
   
   /*
    * schedProc() - Add PROC task to scheduler queue
    *
    * @root = root task
    * @func = task execution function
    * @arg = 1st func argument
    * @pid = PID
    * @opt_data = Optional data
    * @opt_dlen = Optional data length
    * return: NULL error or !=NULL new queued task
    */
   sched_task_t *
   schedProc(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long pid, 
                   void *opt_data, size_t opt_dlen)
   {
           sched_task_t *task;
           void *ptr;
   
           if (!root || !func)
                   return NULL;
   
           /* get new task */
           if (!(task = _sched_useTask(root)))
                   return NULL;
   
           memset(task, 0, sizeof(sched_task_t));
           task->task_id = 0;
           task->task_lock = 0;
           task->task_func = func;
           TASK_TYPE(task) = taskPROC;
           TASK_ROOT(task) = root;
   
           TASK_ARG(task) = arg;
           TASK_VAL(task) = pid;
   
           TASK_DATA(task) = opt_data;
           TASK_DATLEN(task) = opt_dlen;
   
           if (root->root_hooks.hook_add.proc)
                   ptr = root->root_hooks.hook_add.proc(task, NULL);
           else
                   ptr = NULL;
   
           if (!ptr) {
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_lock(&root->root_mtx[taskPROC]);
   #endif
                   TAILQ_INSERT_TAIL(&root->root_proc, task, task_node);
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_unlock(&root->root_mtx[taskPROC]);
   #endif
           } else
                   task = _sched_unuseTask(task);
   
           return task;
   }
   
   /*
    * schedUser() - Add trigger USER task to scheduler queue
    *
    * @root = root task
    * @func = task execution function
    * @arg = 1st func argument
    * @id = Trigger ID
    * @opt_data = Optional data
    * @opt_dlen = Optional data length
    * return: NULL error or !=NULL new queued task
    */
   sched_task_t *
   schedUser(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long id, 
                   void *opt_data, size_t opt_dlen)
   {
           sched_task_t *task;
           void *ptr;
   
           if (!root || !func)
                   return NULL;
   
           /* get new task */
           if (!(task = _sched_useTask(root)))
                   return NULL;
   
           memset(task, 0, sizeof(sched_task_t));
           task->task_id = 0;
           task->task_lock = 0;
           task->task_func = func;
           TASK_TYPE(task) = taskUSER;
           TASK_ROOT(task) = root;
   
           TASK_ARG(task) = arg;
           TASK_VAL(task) = id;
   
           TASK_DATA(task) = opt_data;
           TASK_DATLEN(task) = opt_dlen;
   
           if (root->root_hooks.hook_add.user)
                   ptr = root->root_hooks.hook_add.user(task, NULL);
           else
                   ptr = NULL;
   
           if (!ptr) {
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_lock(&root->root_mtx[taskUSER]);
   #endif
                   TAILQ_INSERT_TAIL(&root->root_user, task, task_node);
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_unlock(&root->root_mtx[taskUSER]);
   #endif
           } else
                   task = _sched_unuseTask(task);
   
           return task;
   }
   
   /*
    * schedSignal() - Add SIGNAL task to scheduler queue
    *
    * @root = root task
    * @func = task execution function
    * @arg = 1st func argument
    * @sig = Signal
    * @opt_data = Optional data
    * @opt_dlen = Optional data length
    * return: NULL error or !=NULL new queued task
    */
   sched_task_t *
   schedSignal(sched_root_task_t * __restrict root, sched_task_func_t func, void *arg, u_long sig, 
                   void *opt_data, size_t opt_dlen)
   {
           sched_task_t *task;
           void *ptr;
   
           if (!root || !func)
                   return NULL;
   
           /* get new task */
           if (!(task = _sched_useTask(root)))
                   return NULL;
   
           memset(task, 0, sizeof(sched_task_t));
           task->task_id = 0;
           task->task_lock = 0;
           task->task_func = func;
           TASK_TYPE(task) = taskSIGNAL;
           TASK_ROOT(task) = root;
   
           TASK_ARG(task) = arg;
           TASK_VAL(task) = sig;
   
           TASK_DATA(task) = opt_data;
           TASK_DATLEN(task) = opt_dlen;
   
           if (root->root_hooks.hook_add.signal)
                   ptr = root->root_hooks.hook_add.signal(task, NULL);
           else
                   ptr = NULL;
   
           if (!ptr) {
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_lock(&root->root_mtx[taskSIGNAL]);
   #endif
                   TAILQ_INSERT_TAIL(&root->root_signal, task, task_node);
   #ifdef HAVE_LIBPTHREAD
                   pthread_mutex_unlock(&root->root_mtx[taskSIGNAL]);
   #endif
           } else
                   task = _sched_unuseTask(task);
   
           return task;
   }
   
   /*
  * schedAlarm() - Add ALARM task to scheduler queue   * schedAlarm() - Add ALARM task to scheduler queue
  *   *
  * @root = root task   * @root = root task

Removed from v.1.8  
changed lines
  Added in v.1.8.2.1


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