diff options
| author | proven <proven@NetBSD.org> | 1993-11-14 22:06:22 +0000 |
|---|---|---|
| committer | proven <proven@NetBSD.org> | 1993-11-14 22:06:22 +0000 |
| commit | 89fc7bac0859332dbb6b0fd0833e74557beadc29 (patch) | |
| tree | 86e4d7e252c6c2d1986520949df2e3190a767e77 /lib/libpthread/pthreads/queue.c | |
| parent | 08322f94235c9fdbef8dc69c9699e836b6caf9d4 (diff) | |
Initial release of the POSIX 1003.4a Draft 7 thread implementation.
Diffstat (limited to 'lib/libpthread/pthreads/queue.c')
| -rw-r--r-- | lib/libpthread/pthreads/queue.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/libpthread/pthreads/queue.c b/lib/libpthread/pthreads/queue.c new file mode 100644 index 00000000000..984760b5a85 --- /dev/null +++ b/lib/libpthread/pthreads/queue.c @@ -0,0 +1,92 @@ +/* ==== queue.c ============================================================ + * Copyright (c) 1993 by Chris Provenzano, proven@athena.mit.edu + * + * Description : Queue functions. + * + * 1.00 93/07/15 proven + * -Started coding this file. + */ + +#include <pthread/copyright.h> +#include <pthread.h> + +/* + * All routines in this file assume that the queue has been appropriatly + * locked. + */ + +/* ========================================================================== + * pthread_queue_init() + */ +void pthread_queue_init(struct pthread_queue *queue) +{ + queue->q_next = NULL; + queue->q_last = NULL; + queue->q_data = NULL; +} + +/* ========================================================================== + * pthread_queue_enq() + */ +void pthread_queue_enq(struct pthread_queue *queue, struct pthread *thread) +{ + if (queue->q_last) { + queue->q_last->next = thread; + } else { + queue->q_next = thread; + } + queue->q_last = thread; + thread->queue = queue; + thread->next = NULL; + +} + +/* ========================================================================== + * pthread_queue_get() + */ +struct pthread *pthread_queue_get(struct pthread_queue *queue) +{ + return(queue->q_next); +} + +/* ========================================================================== + * pthread_queue_deq() + */ +struct pthread *pthread_queue_deq(struct pthread_queue *queue) +{ + struct pthread *thread = NULL; + + if (queue->q_next) { + thread = queue->q_next; + if (!(queue->q_next = queue->q_next->next)) { + queue->q_last = NULL; + } + thread->queue = NULL; + thread->next = NULL; + } + return(thread); +} + +/* ========================================================================== + * pthread_queue_remove() + */ +void pthread_queue_remove(struct pthread_queue *queue, struct pthread *thread) +{ + struct pthread **current = &(queue->q_next); + struct pthread *prev = NULL; + + while (*current) { + if (*current == thread) { + if ((*current)->next) { + *current = (*current)->next; + } else { + queue->q_last = prev; + *current = NULL; + } + } + prev = *current; + current = &((*current)->next); + } + thread->queue = NULL; + thread->next = NULL; +} |
