1 // Copyright (C)2004 Landmark Graphics Corporation 2 // Copyright (C)2007 Sun Microsystems, Inc. 3 // Copyright (C)2011, 2014 D. R. Commander 4 // 5 // This library is free software and may be redistributed and/or modified under 6 // the terms of the wxWindows Library License, Version 3.1 or (at your option) 7 // any later version. The full license is in the LICENSE.txt file included 8 // with this distribution. 9 // 10 // This library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // wxWindows Library License for more details. 14 15 // Thread-safe queue implementation using singly-linked lists 16 17 #ifndef __GENERICQ_H__ 18 #define __GENERICQ_H__ 19 20 #include "Mutex.h" 21 22 23 namespace vglutil 24 { 25 class GenericQ 26 { 27 public: 28 29 typedef void (*SpoilCallback)(void *); 30 31 GenericQ(void); 32 ~GenericQ(void); 33 void add(void *item); 34 void spoil(void *item, SpoilCallback spoilCallback); 35 void get(void **item, bool nonBlocking = false); 36 void release(void); 37 int items(void); 38 39 private: 40 41 typedef struct EntryStruct 42 { 43 void *item; struct EntryStruct *next; 44 } Entry; 45 46 Entry *start, *end; 47 Semaphore hasItem; 48 CriticalSection mutex; 49 int deadYet; 50 }; 51 } 52 53 #endif // __GENERICQ_H__ 54