void thread_enqueue_low (struct thread_master *m, struct thread *thread) { thread->type = THREAD_QUEUE; thread->priority = THREAD_PRIORITY_LOW; thread_list_add (&m->queue_low, thread); }
void thread_enqueue_high (struct thread_master *m, struct thread *thread) { thread->type = THREAD_QUEUE; thread->priority = THREAD_PRIORITY_HIGH; thread_list_add (&m->queue_high, thread); }
void thread_enqueue_middle (struct thread_master *m, struct thread *thread) { thread->type = THREAD_QUEUE; thread->priority = THREAD_PRIORITY_MIDDLE; thread_list_add (&m->queue_middle, thread); }
static void thread_add_timer_common (struct thread_master *m, struct thread *thread) { #ifndef TIMER_NO_SORT struct thread *tt; #endif /* TIMER_NO_SORT */ /* Set index. */ thread->index = m->index; /* Sort by timeval. */ #ifdef TIMER_NO_SORT thread_list_add (&m->timer[m->index], thread); #else for (tt = m->timer[m->index].tail; tt; tt = tt->prev) if (timeval_cmp (thread->u.sands, tt->u.sands) >= 0) break; thread_list_add_after (&m->timer[m->index], tt, thread); #endif /* TIMER_NO_SORT */ /* Increment timer slot index. */ m->index++; m->index %= THREAD_TIMER_SLOT; }
/* Move thread to unuse list. */ static void thread_add_unuse (struct thread_master *m, struct thread *thread) { assert (m != NULL); assert (thread->next == NULL); assert (thread->prev == NULL); assert (thread->type == THREAD_UNUSED); thread_list_add (&m->unuse, thread); }
/* Add pending read thread. */ struct thread * thread_add_read_pend (struct lib_globals *zg, int (*func) (struct thread *), void *arg, int val) { struct thread *thread; struct thread_master *m = zg->master; pal_assert (m != NULL); thread = thread_get (zg, THREAD_READ_PEND, func, arg); if (thread == NULL) return NULL; thread->u.val = val; thread_list_add (&m->read_pend, thread); return thread; }
/* Add low priority event thread. */ struct thread * thread_add_event_low (struct lib_globals *zg, int (*func) (struct thread *), void *arg, int val) { struct thread *thread; struct thread_master *m = zg->master; pal_assert (m != NULL); thread = thread_get (zg, THREAD_EVENT_LOW, func, arg); if (thread == NULL) return NULL; thread->u.val = val; thread_list_add (&m->event_low, thread); return thread; }
/* Add simple event thread. */ struct thread * thread_add_event (struct thread_master *master, int (*func) (struct thread *), void *arg, int val) { struct thread *thread; struct thread_master *m = master; assert (m != NULL); thread = thread_get (m, THREAD_EVENT, func, arg); if (thread == NULL) return NULL; thread->u.val = val; thread_list_add (&m->event, thread); return thread; }
/* Add new write thread. */ struct thread * thread_add_write (struct lib_globals *zg, int (*func) (struct thread *), void *arg, int fd) { struct thread_master *m = zg->master; struct thread *thread; pal_assert (m != NULL); if (fd < 0 || PAL_SOCK_HANDLESET_ISSET (fd, &m->writefd)) return NULL; thread = thread_get (zg, THREAD_WRITE, func, arg); if (thread == NULL) return NULL; thread_update_max_fd (m, fd); PAL_SOCK_HANDLESET_SET (fd, &m->writefd); thread->u.fd = fd; thread_list_add (&m->write, thread); return thread; }
/* Add new high priority read thread. */ struct thread * thread_add_read_high (struct thread_master *master, int (*func) (struct thread *), void *arg, int fd) { struct thread_master *m = master; struct thread *thread; assert (m != NULL); if (fd < 0) return NULL; thread = thread_get (master, THREAD_READ_HIGH, func, arg); if (thread == NULL) return NULL; thread_update_max_fd (m, fd); PAL_SOCK_HANDLESET_SET (fd, &m->readfd); thread->u.fd = fd; thread_list_add (&m->read_high, thread); return thread; }