From d74c7a00c417cffdc93a82efa2841e23d823bea6 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 19 May 2005 14:10:22 +0000 Subject: Multithreading rulez? --- src/queue.h | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'src/queue.h') diff --git a/src/queue.h b/src/queue.h index de7b8ff..7c56e93 100644 --- a/src/queue.h +++ b/src/queue.h @@ -38,6 +38,10 @@ /* * $Log$ + * Revision 1.16 2005/05/19 14:10:22 deva + * + * Multithreading rulez? + * * Revision 1.15 2005/05/16 16:00:57 deva * * Lots of stuff! @@ -82,6 +86,7 @@ public: ~Queue(); void push(T *t); + void bpush(T *t); T *pop(); T *peek(); @@ -127,9 +132,6 @@ Queue::~Queue() pthread_mutex_destroy(&mutex); } - - - /** * Push element on queue. */ @@ -171,6 +173,47 @@ void Queue::push(T *t) pthread_mutex_unlock(&mutex); } +/** + * Push element on queue from the bottom. + */ +template +void Queue::bpush(T *t) +{ + if(locked) { + delete t; + return; + } + + pthread_mutex_lock(&mutex); + + buf_t *b = (buf_t*)xmalloc(sizeof(*b)); + b->data = (void*)t; + + assert(b != NULL); + + if(limit && count > 0) { + T* tmp = (T*)_pop(); + delete tmp; + } + + if(!head) { + head = tail = b; + b->next = b->prev = NULL; + count = 1; + pthread_mutex_unlock(&mutex); + return; + } + + b->prev = head; + b->next = NULL; + if(head) + head->next = b; + head = b; + count++; + + pthread_mutex_unlock(&mutex); +} + /** * Pop element from queue. * If queue is empty, NULL is returned. -- cgit v1.2.3