aboutsummaryrefslogtreecommitdiff
path: root/src/itoatom.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/itoatom.h')
-rw-r--r--src/itoatom.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/itoatom.h b/src/itoatom.h
new file mode 100644
index 0000000..7fc9090
--- /dev/null
+++ b/src/itoatom.h
@@ -0,0 +1,56 @@
1#ifndef BU_ITO_QUEUE_H
2#define BU_ITO_QUEUE_H
3
4#include <pthread.h>
5
6#include "itomutex.h"
7#include "itocondition.h"
8
9/**
10 * A thread-safe wrapper class.
11 *@author Mike Buland
12 */
13template <class T>
14class ItoAtom
15{
16public:
17 /**
18 * Construct an empty queue.
19 */
20 ItoAtom()
21 {
22 }
23
24 ItoAtom( const T &src ) :
25 data( src )
26 {
27 }
28
29 ~ItoQueue()
30 {
31 }
32
33 T get()
34 {
35 mOperate.lock();
36 mOperate.unlock();
37 return data;
38 }
39
40 void set( const T &val )
41 {
42 mOperate.lock();
43 data = val;
44 cBlock.signal();
45 mOperate.unlock();
46 }
47
48private:
49 Item *pStart; /**< The start of the queue, the next element to dequeue. */
50 Item *pEnd; /**< The end of the queue, the last element to dequeue. */
51
52 ItoMutex mOperate; /**< The master mutex, used on all operations. */
53 ItoCondition cBlock; /**< The condition for blocking dequeues. */
54};
55
56#endif