diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-04-26 15:06:49 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-04-26 15:06:49 +0000 |
commit | 530014a3cce53e86dce8917e98a4e86d02f176aa (patch) | |
tree | c667c996fb91692b101f75296206b8420f19bf73 /src/itoatom.h | |
parent | 066282ae6de25cf92780dbdaa2fd70a033e95659 (diff) | |
download | libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.gz libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.bz2 libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.tar.xz libbu++-530014a3cce53e86dce8917e98a4e86d02f176aa.zip |
Merged Ito and put it in the BU namespace. I should probably clean up the
formatting on the comments, some of the lines wrap, but I'm not too worried
about it right now. I also fixed up the doxygen config and build.conf files
so that everything is building nice and smooth now.
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..96090f2 --- /dev/null +++ b/src/itoatom.h | |||
@@ -0,0 +1,56 @@ | |||
1 | #ifndef ITO_QUEUE_H | ||
2 | #define 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 | ||