hub/queue.h

Go to the documentation of this file.
00001 #ifndef utu_queue_h
00002 #define utu_queue_h
00003 
00004 /*
00005  * Utu -- Saving The Internet With Hate
00006  *
00007  * Copyright (c) Zed A. Shaw 2005 (zedshaw@zedshaw.com)
00008  *
00009  * This file is modifiable/redistributable under the terms of the GNU
00010  * General Public License.
00011  *
00012  * You should have recieved a copy of the GNU General Public License along
00013  * with this program; see the file COPYING. If not, write to the Free Software
00014  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 0211-1307, USA.
00015  */
00016 
00017 
00018 
00019 #include <myriad/sglib.h>
00020 #include "protocol/message.h"
00021 
00046 typedef struct MsgQueue {
00047   Message **messages;
00048   Rendez read_wait;
00049   int dead;
00050 
00051   size_t i;
00052   size_t j;
00053   size_t dim;
00054 } MsgQueue;
00055 
00067 MsgQueue *MsgQueue_create(size_t length);
00068 
00070 #define MsgQueue_is_empty(Q) ((Q)->i == (Q)->j)
00071 
00073 #define MsgQueue_is_full(Q) (((Q)->i)==(((Q)->j)+1)%((Q)->dim))
00074 
00076 #define MsgQueue_get_first(Q) ((Q)->messages[(Q)->i])
00077 
00079 Message *MsgQueue_first(MsgQueue *queue);
00080 
00087 int MsgQueue_add(MsgQueue *q, Message *message);
00088 
00096 int MsgQueue_delete(MsgQueue *q);
00097 
00099 #define MsgQueue_mark_dead(Q) (Q)->dead = 1
00100 
00102 #define MsgQueue_is_dead(Q) (Q)->dead
00103 
00104 #define MsgQueue_wake_all(Q) taskwakeupall(&((Q)->read_wait))
00105 
00106 #define MsgQueue_wait(Q) tasksleep(&(Q)->read_wait)
00107 
00113 void MsgQueue_destroy(MsgQueue *q);
00114 
00116 #define MsgQueue_clear(Q) if(Q) (Q)->i = (Q)->j = 0;
00117 
00118 #endif

Generated on Tue Apr 10 01:00:18 2007 for Utu by  doxygen 1.5.1