diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
commit | ac517a2b7625e0aa0862679e961c6349f859ea3b (patch) | |
tree | e3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/itoatom.h | |
parent | f8d4301e9fa4f3709258505941e37fab2eadadc6 (diff) | |
parent | bd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff) | |
download | libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2 libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip |
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to 'src/itoatom.h')
-rw-r--r-- | src/itoatom.h | 56 |
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 | */ | ||
13 | template <class T> | ||
14 | class ItoAtom | ||
15 | { | ||
16 | public: | ||
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 | |||
48 | private: | ||
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 | ||