diff options
author | deva <deva> | 2005-05-19 14:10:22 +0000 |
---|---|---|
committer | deva <deva> | 2005-05-19 14:10:22 +0000 |
commit | d74c7a00c417cffdc93a82efa2841e23d823bea6 (patch) | |
tree | ea7f7b69ccbd0dc1df1ea5e05dd59cfafa194f25 /src/queue.h | |
parent | a597454b7ce1b931e3e4117e6fed509cc22517ff (diff) |
Multithreading rulez?R0_2_2
Diffstat (limited to 'src/queue.h')
-rw-r--r-- | src/queue.h | 49 |
1 files changed, 46 insertions, 3 deletions
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<T>::~Queue() pthread_mutex_destroy(&mutex); } - - - /** * Push element on queue. */ @@ -172,6 +174,47 @@ void Queue<T>::push(T *t) } /** + * Push element on queue from the bottom. + */ +template<typename T> +void Queue<T>::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. */ |