• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/ap/gpl/zebra/lib/

Lines Matching refs:thread

26 #include "thread.h"
96 /* Allocate new thread master. */
104 /* Add a new thread to the list. */
106 thread_list_add (struct thread_list *list, struct thread *thread)
108 thread->next = NULL;
109 thread->prev = list->tail;
111 list->tail->next = thread;
113 list->head = thread;
114 list->tail = thread;
118 /* Add a new thread just before the point. */
121 struct thread *point,
122 struct thread *thread)
124 thread->next = point;
125 thread->prev = point->prev;
127 point->prev->next = thread;
129 list->head = thread;
130 point->prev = thread;
134 /* Delete a thread from the list. */
135 static struct thread *
136 thread_list_delete (struct thread_list *list, struct thread *thread)
138 if (thread->next)
139 thread->next->prev = thread->prev;
141 list->tail = thread->prev;
142 if (thread->prev)
143 thread->prev->next = thread->next;
145 list->head = thread->next;
146 thread->next = thread->prev = NULL;
148 return thread;
151 /* Move thread to unuse list. */
153 thread_add_unuse (struct thread_master *m, struct thread *thread)
156 assert (thread->next == NULL);
157 assert (thread->prev == NULL);
158 assert (thread->type == THREAD_UNUSED);
159 thread_list_add (&m->unuse, thread);
162 /* Free all unused thread. */
166 struct thread *t;
167 struct thread *next;
178 /* Stop thread scheduler. */
193 static struct thread *
210 thread_timer_remain_second (struct thread *thread)
216 if (thread->u.sands.tv_sec - timer_now.tv_sec > 0)
217 return thread->u.sands.tv_sec - timer_now.tv_sec;
222 /* Get new thread. */
223 static struct thread *
225 int (*func) (struct thread *), void *arg)
227 struct thread *thread;
230 thread = thread_trim_head (&m->unuse);
233 thread = XCALLOC (MTYPE_THREAD, sizeof (struct thread));
236 thread->type = type;
237 thread->master = m;
238 thread->func = func;
239 thread->arg = arg;
241 return thread;
244 /* Add new read thread. */
245 struct thread *
247 int (*func) (struct thread *), void *arg, int fd)
249 struct thread *thread;
261 thread = thread_get (m, THREAD_READ, func, arg);
263 thread->u.fd = fd;
264 thread_list_add (&m->read, thread);
266 return thread;
269 /* Add new write thread. */
270 struct thread *
272 int (*func) (struct thread *), void *arg, int fd)
274 struct thread *thread;
286 thread = thread_get (m, THREAD_WRITE, func, arg);
288 thread->u.fd = fd;
289 thread_list_add (&m->write, thread);
291 return thread;
294 /* Add timer event thread. */
295 struct thread *
297 int (*func) (struct thread *), void *arg, long timer)
300 struct thread *thread;
302 struct thread *tt;
307 thread = thread_get (m, THREAD_TIMER, func, arg);
312 thread->u.sands = timer_now;
316 thread_list_add (&m->timer, thread);
319 if (timeval_cmp (thread->u.sands, tt->u.sands) <= 0)
323 thread_list_add_before (&m->timer, tt, thread);
325 thread_list_add (&m->timer, thread);
328 return thread;
331 /* Add simple event thread. */
332 struct thread *
334 int (*func) (struct thread *), void *arg, int val)
336 struct thread *thread;
340 thread = thread_get (m, THREAD_EVENT, func, arg);
341 thread->u.val = val;
342 thread_list_add (&m->event, thread);
344 return thread;
347 /* Cancel thread from scheduler. */
349 thread_cancel (struct thread *thread)
351 switch (thread->type)
354 assert (FD_ISSET (thread->u.fd, &thread->master->readfd));
355 FD_CLR (thread->u.fd, &thread->master->readfd);
356 thread_list_delete (&thread->master->read, thread);
359 assert (FD_ISSET (thread->u.fd, &thread->master->writefd));
360 FD_CLR (thread->u.fd, &thread->master->writefd);
361 thread_list_delete (&thread->master->write, thread);
364 thread_list_delete (&thread->master->timer, thread);
367 thread_list_delete (&thread->master->event, thread);
370 thread_list_delete (&thread->master->ready, thread);
375 thread->type = THREAD_UNUSED;
376 thread_add_unuse (thread->master, thread);
383 struct thread *thread;
385 thread = m->event.head;
386 while (thread)
388 struct thread *t;
390 t = thread;
391 thread = t->next;
413 for (thread = m->timer.head; thread; thread = thread->next)
416 timer_wait = &thread->u.sands;
417 else if (timeval_cmp (thread->u.sands, *timer_wait) < 0)
418 timer_wait = &thread->u.sands;
466 struct thread *
467 thread_run (struct thread_master *m, struct thread *thread,
468 struct thread *fetch)
470 *fetch = *thread;
471 thread->type = THREAD_UNUSED;
472 thread_add_unuse (m, thread);
480 struct thread *thread;
481 struct thread *next;
484 for (thread = list->head; thread; thread = next)
486 next = thread->next;
488 if (FD_ISSET (THREAD_FD (thread), fdset))
490 assert (FD_ISSET (THREAD_FD (thread), mfdset));
491 FD_CLR(THREAD_FD (thread), mfdset);
492 thread_list_delete (list, thread);
493 thread_list_add (&m->ready, thread);
494 thread->type = THREAD_READY;
501 /* Fetch next ready thread. */
502 struct thread *
503 thread_fetch (struct thread_master *m, struct thread *fetch)
507 struct thread *thread;
522 if ((thread = thread_trim_head (&m->event)) != NULL)
523 return thread_run (m, thread, fetch);
528 for (thread = m->timer.head; thread; thread = thread->next)
529 if (timeval_cmp (timer_now, thread->u.sands) >= 0)
531 thread_list_delete (&m->timer, thread);
532 return thread_run (m, thread, fetch);
536 if ((thread = thread_trim_head (&m->ready)) != NULL)
537 return thread_run (m, thread, fetch);
568 if ((thread = thread_trim_head (&m->ready)) != NULL)
569 return thread_run (m, thread, fetch);
593 thread_should_yield (struct thread *thread)
599 if (thread_consumed_time (&ru, &thread->ru) > THREAD_YIELD_TIME_SLOT)
605 /* We check thread consumed time. If the system has getrusage, we'll
606 use that to get indepth stats on the performance of the thread. If
609 thread_call (struct thread *thread)
614 GETRUSAGE (&thread->ru);
616 (*thread->func) (thread);
620 thread_time = thread_consumed_time (&ru, &thread->ru);
633 (unsigned long) thread->func,
640 /* Execute thread */
641 struct thread *
643 int (*func)(struct thread *),
647 struct thread dummy;
649 memset (&dummy, 0, sizeof (struct thread));