diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-02-13 16:50:08 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-02-13 16:50:08 +0000 |
commit | b8dd8d973dc29063c7c2ae2fa52386ebb215aecb (patch) | |
tree | 03d61c4af7a292e4bcfb2c4efd99a99cb6038bd7 | |
parent | d66d62236b3354e26157efa91689d1a22ae3866d (diff) | |
download | libbu++-b8dd8d973dc29063c7c2ae2fa52386ebb215aecb.tar.gz libbu++-b8dd8d973dc29063c7c2ae2fa52386ebb215aecb.tar.bz2 libbu++-b8dd8d973dc29063c7c2ae2fa52386ebb215aecb.tar.xz libbu++-b8dd8d973dc29063c7c2ae2fa52386ebb215aecb.zip |
What the HELL was I thinking? Apparently ItoAtom was never used, and it's so
handy too...
It wasn't in the right namespace, it was broken, it had pieces that were
misnamed...bleh...anyway, it complies and works now.
Diffstat (limited to '')
-rw-r--r-- | src/itoatom.h | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/src/itoatom.h b/src/itoatom.h index 2791519..5d4db0e 100644 --- a/src/itoatom.h +++ b/src/itoatom.h | |||
@@ -5,59 +5,60 @@ | |||
5 | * terms of the license contained in the file LICENSE. | 5 | * terms of the license contained in the file LICENSE. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #ifndef BU_ITO_QUEUE_H | 8 | #ifndef BU_ITO_ATOM_H |
9 | #define BU_ITO_QUEUE_H | 9 | #define BU_ITO_ATOM_H |
10 | 10 | ||
11 | #include <pthread.h> | 11 | #include <pthread.h> |
12 | 12 | ||
13 | #include "itomutex.h" | 13 | #include "itomutex.h" |
14 | #include "itocondition.h" | 14 | #include "itocondition.h" |
15 | 15 | ||
16 | /** | 16 | namespace Bu |
17 | * A thread-safe wrapper class. | ||
18 | *@ingroup Threading | ||
19 | */ | ||
20 | template <class T> | ||
21 | class ItoAtom | ||
22 | { | 17 | { |
23 | public: | ||
24 | /** | 18 | /** |
25 | * Construct an empty queue. | 19 | * A thread-safe wrapper class. |
20 | *@ingroup Threading | ||
26 | */ | 21 | */ |
27 | ItoAtom() | 22 | template <class T> |
23 | class ItoAtom | ||
28 | { | 24 | { |
29 | } | 25 | public: |
26 | /** | ||
27 | * Construct an empty queue. | ||
28 | */ | ||
29 | ItoAtom() | ||
30 | { | ||
31 | } | ||
30 | 32 | ||
31 | ItoAtom( const T &src ) : | 33 | ItoAtom( const T &src ) : |
32 | data( src ) | 34 | data( src ) |
33 | { | 35 | { |
34 | } | 36 | } |
35 | 37 | ||
36 | ~ItoQueue() | 38 | ~ItoAtom() |
37 | { | 39 | { |
38 | } | 40 | } |
39 | 41 | ||
40 | T get() | 42 | T get() |
41 | { | 43 | { |
42 | mOperate.lock(); | 44 | mOperate.lock(); |
43 | mOperate.unlock(); | 45 | T ret = data; |
44 | return data; | 46 | mOperate.unlock(); |
45 | } | 47 | return ret; |
48 | } | ||
46 | 49 | ||
47 | void set( const T &val ) | 50 | void set( const T &val ) |
48 | { | 51 | { |
49 | mOperate.lock(); | 52 | mOperate.lock(); |
50 | data = val; | 53 | data = val; |
51 | cBlock.signal(); | 54 | mOperate.unlock(); |
52 | mOperate.unlock(); | 55 | } |
53 | } | 56 | |
54 | 57 | private: | |
55 | private: | 58 | T data; |
56 | Item *pStart; /**< The start of the queue, the next element to dequeue. */ | 59 | |
57 | Item *pEnd; /**< The end of the queue, the last element to dequeue. */ | 60 | ItoMutex mOperate; /**< The master mutex, used on all operations. */ |
58 | 61 | }; | |
59 | ItoMutex mOperate; /**< The master mutex, used on all operations. */ | ||
60 | ItoCondition cBlock; /**< The condition for blocking dequeues. */ | ||
61 | }; | 62 | }; |
62 | 63 | ||
63 | #endif | 64 | #endif |