evq_queue.h

Go to the documentation of this file.
00001 // This API is inspired by Python's Queue.
00002 
00003 #ifndef __EVQ_QUEUE_H__
00004 #define __EVQ_QUEUE_H__
00005 
00006 #include <pthread.h>
00007 
00008 typedef struct __QueueItem {
00009   struct __QueueItem* next;
00010 } QueueItem;
00011 
00012 typedef struct {
00013   QueueItem* head;
00014   QueueItem* tail;
00015   pthread_mutex_t mutex;
00016   pthread_cond_t cond;
00017   int running;
00018 } Queue;
00019 
00020 void queue_init(Queue* q);
00021 
00022 // Appends the passed item without blocking.
00023 // The passed structure is modified.
00024 // Ownership is not taken.
00025 // Does nothing if the queue has been stopped.
00026 void queue_put(Queue* q, QueueItem* item);
00027 
00028 // Removes the specified item, if it is in the queue.
00029 // Does nothing if the queue has been stopped.
00030 void queue_remove(Queue* q, QueueItem* item);
00031 
00032 // Blocks until an item becomes available.
00033 // Returns NULL if the queue has been stopped.
00034 QueueItem* queue_get(Queue* q);
00035 
00036 // Releases all blocking getters.
00037 // After the queue has been stopped, all puts will be ineffective,
00038 // and all gets will return immediately with a NULL value.
00039 void queue_stop(Queue* q);
00040 
00041 // Frees internal resources, but the elements (QueueItem objects) are not freed.
00042 // After calling this, do not attempt to use the queue any longer.
00043 // You may not call this function more than once.
00044 void queue_close(Queue* q);
00045 
00046 #endif // __EVQ_QUEUE_H__
00047 
00048 /**
00049 
00050 evq_queue.h
00051 
00052 Copyright 2009 Helsinki Institute for Information Technology (HIIT)
00053 and the authors. All rights reserved.
00054 
00055 Authors: Tero Hasu <tero.hasu@hut.fi>
00056 
00057 Permission is hereby granted, free of charge, to any person
00058 obtaining a copy of this software and associated documentation files
00059 (the "Software"), to deal in the Software without restriction,
00060 including without limitation the rights to use, copy, modify, merge,
00061 publish, distribute, sublicense, and/or sell copies of the Software,
00062 and to permit persons to whom the Software is furnished to do so,
00063 subject to the following conditions:
00064 
00065 The above copyright notice and this permission notice shall be
00066 included in all copies or substantial portions of the Software.
00067 
00068 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00069 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00070 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00071 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
00072 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
00073 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00074 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00075 SOFTWARE.
00076 
00077  **/

ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1