20 #ifndef __GENQUEUE_H__ 21 #define __GENQUEUE_H__ 23 #include <csutil/ref.h> 24 #include <csutil/threading/mutex.h> 25 #include <csutil/threading/condition.h> 38 template <
class queuetype,
template <
class T>
class refType = csRef >
58 bool AddWait(queuetype* msg, csTicks timeout = 0)
61 CS::Threading::RecursiveMutexScopedLock lock(
mutex);
64 bool added =
Add(msg);
69 Error1(
"Queue full! Waiting.\n");
82 bool Add(queuetype* msg)
86 CS::Threading::RecursiveMutexScopedLock lock(
mutex);
88 if (!msg->GetPending())
98 CS_ASSERT(msg->GetRefCount() > 0);
103 msg->SetPending(
true);
113 CS::Threading::RecursiveMutexScopedLock lock(
mutex);
115 csRef<queuetype> ptr;
117 unsigned int qpointer =
qstart;
120 while(!ptr.IsValid())
123 if (qpointer ==
qend)
131 qpointer = (qpointer + 1) %
qsize;
134 return csPtr<queuetype>(ptr);
144 CS::Threading::RecursiveMutexScopedLock lock(
mutex);
146 csRef<queuetype> ptr;
149 while(!ptr.IsValid())
165 ptr->SetPending(
false);
168 return csPtr<queuetype>(ptr);
175 CS::Threading::RecursiveMutexScopedLock lock(
mutex);
178 csRef<queuetype> temp =
Get();
181 return csPtr<queuetype> (temp);
209 CS::Threading::RecursiveMutexScopedLock lock(
mutex);
218 CS::Threading::RecursiveMutexScopedLock lock(
mutex);
225 CS::Threading::RecursiveMutex
mutex;
refType< queuetype > * qbuffer
unsigned int Count()
Number of items in the queue.
csPtr< queuetype > Peek()
bool AddWait(queuetype *msg, csTicks timeout=0)
like above, but waits to add the next message, if the queue is full be careful with this...
csPtr< queuetype > Get()
This gets the next message from the queue, it is then removed from the queue.
CS::Threading::RecursiveMutex mutex
bool Add(queuetype *msg)
This adds a message to the queue and waits if it is full.
GenericRefQueue(unsigned int maxsize=500)
A queue of smart pointers with locking facilties for multi-threading.
csPtr< queuetype > GetWait(csTicks timeout)
like above, but waits for the next message, if the queue is empty
void Interrupt()
This function interrupt the queue if it is waiting.
CS::Threading::Condition datacondition