8#if __has_include("defs.h")
71 criticalsection update;
86template <
class M,
class C = std::deque<M>>
94 if (limit > 0 && limit < INFINITE)
100 virtual bool produce (
const M& obj, DWORD timeout = INFINITE)
102 if (limit < INFINITE)
106 if (timeout != INFINITE)
109 while (std::queue<M, C>::size () >= limit)
112 if (timeout != INFINITE)
114 int t_wait = timeout - (int)t.
msecLap ();
122 std::queue<M, C>::push (obj);
130 std::queue<M, C>::push (obj);
138 virtual bool consume (M& result,
int timeout = INFINITE)
140 if (timeout != INFINITE)
146 while (std::queue<M, C>::empty ())
149 t_wait = timeout - (int)t.
msecLap ();
159 if (std::queue<M, C>::empty ())
166 if (!std::queue<M, C>::empty ())
171 result = std::queue<M, C>::front ();
172 std::queue<M, C>::pop ();
173 if (limit != INFINITE)
184 return std::queue<M, C>::empty ();
191 return (std::queue<M, C>::size () == limit);
198 return std::queue<M, C>::size ();
A template class that implements "asynchronous queues".
Definition syncque.h:88
bool empty()
Return true if queue is empty.
Definition syncque.h:181
virtual bool consume(M &result, int timeout=INFINITE)
Definition syncque.h:138
bool full()
Return true if queue is at capacity.
Definition syncque.h:188
semaphore prod_sema
producers' semaphore counts down until queue is full
Definition syncque.h:203
semaphore cons_sema
consumers' semaphore counts down until queue is empty
Definition syncque.h:204
size_t size()
Return queue size.
Definition syncque.h:195
criticalsection update
critical section protects queue's integrity
Definition syncque.h:205
virtual bool produce(const M &obj, DWORD timeout=INFINITE)
Definition syncque.h:100
async_queue(size_t limit_=INFINITE)
Crates a queue with the given maximum size.
Definition syncque.h:91
Lightweight inter-thread synchronization.
Definition critsect.h:25
virtual void enter()
Enter critical section.
Definition critsect.h:97
virtual void leave()
Leave critical section.
Definition critsect.h:109
Automatic wrapper for critical sections.
Definition critsect.h:69
Wrapper for Windows semaphore objects.
Definition semaphore.h:16
int signal(int count=1)
Signal a semaphore object.
Definition semaphore.cpp:45
Simple stopwatch timer (yet another one!)
Definition stopwatch.h:20
double msecLap()
Return number of milliseconds elapsed from start.
Definition stopwatch.cpp:42
void start()
Start the stopwatch.
Definition stopwatch.cpp:25
A template class that implements a "synchronous queue", in effect a mailbox that can store one "messa...
Definition syncque.h:33
sync_queue()
Create a synchronous queue.
Definition syncque.h:36
void produce(const M &obj)
Put new element in queue.
Definition syncque.h:41
virtual void wait()
Wait for object to become signaled.
Definition syncbase.h:86
criticalsection and lock classes
semaphore class definition
Definition of stopwatch class.