00001 00002 00003 00004 00005 00006 00007 00008 // =========================================================== 00009 // 00010 // Copyright (C) 2005-2007, all rights reserved by 00011 // - Institute of Telematics, Universitaet Karlsruhe (TH) 00012 // 00013 // More information and contact: 00014 // https://projekte.tm.uka.de/trac/NSIS 00015 // 00016 // This program is free software; you can redistribute it and/or modify 00017 // it under the terms of the GNU General Public License as published by 00018 // the Free Software Foundation; version 2 of the License 00019 // 00020 // This program is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 // GNU General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU General Public License along 00026 // with this program; if not, write to the Free Software Foundation, Inc., 00027 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00028 // 00029 // =========================================================== 00043 #ifndef QUEUE_TYPE 00044 #define QUEUE_TYPE 00045 00046 #include <pthread.h> 00047 00048 #define ELEMENT_BLOCKSIZE 64 00049 #define MAX_QUEUENAME_LENGTH 32 00050 00051 00052 /* queue element block type */ 00053 typedef struct queue_elblock_struct 00054 { 00055 void *element[ELEMENT_BLOCKSIZE]; 00056 int read, write; 00057 struct queue_elblock_struct *next_block; 00058 } 00059 queue_elblock_t; 00060 00061 00062 typedef struct queue_struct 00063 { 00064 pthread_mutex_t mutex; 00065 pthread_mutexattr_t mutex_attr; 00066 pthread_cond_t cond; 00067 00068 unsigned long nr_of_elements; 00069 unsigned long exp_nr_of_elements; 00070 int exp_enabled; 00071 queue_elblock_t *first_block; 00072 queue_elblock_t *last_block; 00073 queue_elblock_t *exp_first_block; 00074 queue_elblock_t *exp_last_block; 00075 //#ifdef QUEUELEN 00076 unsigned long queue_maxlength; 00077 //#endif 00078 char name[MAX_QUEUENAME_LENGTH +1]; 00079 } 00080 queue_t; 00081 00082 extern queue_t *create_queue (const char *name); 00083 extern int enqueue_element_signal (queue_t * queuehead, void *element); 00084 extern int enqueue_element_expedited_signal (queue_t * queuehead, void *element, int exp); 00085 extern void *dequeue_element_wait (queue_t * queuehead); 00086 extern void *dequeue_element_timedwait(queue_t *queuehead, const struct timespec *tspec); 00087 extern int destroy_queue (queue_t * queuehead); 00088 extern void *dequeue_element_nonblocking(queue_t * queuehead); 00089 extern unsigned long queue_nr_of_elements(queue_t *queue); 00090 extern int queue_is_expedited_enabled(queue_t *queue); 00091 extern int queue_enable_expedited(queue_t *queue, int exp); 00092 00093 #endif 00094