diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/synchroheap.h | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/synchroheap.h')
-rw-r--r-- | src/stable/synchroheap.h | 262 |
1 files changed, 131 insertions, 131 deletions
diff --git a/src/stable/synchroheap.h b/src/stable/synchroheap.h index 9448625..f5216bf 100644 --- a/src/stable/synchroheap.h +++ b/src/stable/synchroheap.h | |||
@@ -14,137 +14,137 @@ | |||
14 | 14 | ||
15 | namespace Bu | 15 | namespace Bu |
16 | { | 16 | { |
17 | template<typename item, typename cmpfunc=__basicLTCmp<item>, | 17 | template<typename item, typename cmpfunc=__basicLTCmp<item>, |
18 | typename itemalloc=std::allocator<item> > | 18 | typename itemalloc=std::allocator<item> > |
19 | class SynchroHeap | 19 | class SynchroHeap |
20 | { | 20 | { |
21 | public: | 21 | public: |
22 | SynchroHeap() | 22 | SynchroHeap() |
23 | { | 23 | { |
24 | } | 24 | } |
25 | 25 | ||
26 | virtual ~SynchroHeap() | 26 | virtual ~SynchroHeap() |
27 | { | 27 | { |
28 | } | 28 | } |
29 | 29 | ||
30 | void enqueue( item i ) | 30 | void enqueue( item i ) |
31 | { | 31 | { |
32 | imData.lock(); | 32 | imData.lock(); |
33 | hData.enqueue( i ); | 33 | hData.enqueue( i ); |
34 | icBlock.signal(); | 34 | icBlock.signal(); |
35 | imData.unlock(); | 35 | imData.unlock(); |
36 | } | 36 | } |
37 | 37 | ||
38 | item dequeue( bool bBlock=false ) | 38 | item dequeue( bool bBlock=false ) |
39 | { | 39 | { |
40 | imData.lock(); | 40 | imData.lock(); |
41 | if( hData.isEmpty() ) | 41 | if( hData.isEmpty() ) |
42 | { | 42 | { |
43 | imData.unlock(); | 43 | imData.unlock(); |
44 | 44 | ||
45 | if( bBlock ) | 45 | if( bBlock ) |
46 | { | 46 | { |
47 | icBlock.lock(); | 47 | icBlock.lock(); |
48 | 48 | ||
49 | while( hData.isEmpty() ) | 49 | while( hData.isEmpty() ) |
50 | icBlock.wait(); | 50 | icBlock.wait(); |
51 | 51 | ||
52 | imData.lock(); | 52 | imData.lock(); |
53 | try | 53 | try |
54 | { | 54 | { |
55 | item iRet = hData.dequeue(); | 55 | item iRet = hData.dequeue(); |
56 | imData.unlock(); | 56 | imData.unlock(); |
57 | icBlock.unlock(); | 57 | icBlock.unlock(); |
58 | return iRet; | 58 | return iRet; |
59 | } | 59 | } |
60 | catch(...) | 60 | catch(...) |
61 | { | 61 | { |
62 | imData.unlock(); | 62 | imData.unlock(); |
63 | icBlock.unlock(); | 63 | icBlock.unlock(); |
64 | throw; | 64 | throw; |
65 | } | 65 | } |
66 | } | 66 | } |
67 | throw HeapException("Heap empty."); | 67 | throw HeapException("Heap empty."); |
68 | } | 68 | } |
69 | else | 69 | else |
70 | { | 70 | { |
71 | try | 71 | try |
72 | { | 72 | { |
73 | item iRet = hData.dequeue(); | 73 | item iRet = hData.dequeue(); |
74 | imData.unlock(); | 74 | imData.unlock(); |
75 | return iRet; | 75 | return iRet; |
76 | } | 76 | } |
77 | catch(...) | 77 | catch(...) |
78 | { | 78 | { |
79 | imData.unlock(); | 79 | imData.unlock(); |
80 | throw; | 80 | throw; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | } | 83 | } |
84 | 84 | ||
85 | item dequeue( int iSec, int iUSec ) | 85 | item dequeue( int iSec, int iUSec ) |
86 | { | 86 | { |
87 | imData.lock(); | 87 | imData.lock(); |
88 | if( hData.isEmpty() ) | 88 | if( hData.isEmpty() ) |
89 | { | 89 | { |
90 | imData.unlock(); | 90 | imData.unlock(); |
91 | 91 | ||
92 | icBlock.lock(); | 92 | icBlock.lock(); |
93 | 93 | ||
94 | icBlock.wait( iSec, iUSec ); | 94 | icBlock.wait( iSec, iUSec ); |
95 | 95 | ||
96 | imData.lock(); | 96 | imData.lock(); |
97 | try | 97 | try |
98 | { | 98 | { |
99 | item iRet = hData.dequeue(); | 99 | item iRet = hData.dequeue(); |
100 | imData.unlock(); | 100 | imData.unlock(); |
101 | icBlock.unlock(); | 101 | icBlock.unlock(); |
102 | return iRet; | 102 | return iRet; |
103 | } | 103 | } |
104 | catch(...) | 104 | catch(...) |
105 | { | 105 | { |
106 | imData.unlock(); | 106 | imData.unlock(); |
107 | icBlock.unlock(); | 107 | icBlock.unlock(); |
108 | throw; | 108 | throw; |
109 | } | 109 | } |
110 | } | 110 | } |
111 | else | 111 | else |
112 | { | 112 | { |
113 | try | 113 | try |
114 | { | 114 | { |
115 | item iRet = hData.dequeue(); | 115 | item iRet = hData.dequeue(); |
116 | imData.unlock(); | 116 | imData.unlock(); |
117 | return iRet; | 117 | return iRet; |
118 | } | 118 | } |
119 | catch(...) | 119 | catch(...) |
120 | { | 120 | { |
121 | imData.unlock(); | 121 | imData.unlock(); |
122 | throw; | 122 | throw; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | } | 125 | } |
126 | 126 | ||
127 | bool isEmpty() | 127 | bool isEmpty() |
128 | { | 128 | { |
129 | imData.lock(); | 129 | imData.lock(); |
130 | bool bRet = hData.isEmpty(); | 130 | bool bRet = hData.isEmpty(); |
131 | imData.unlock(); | 131 | imData.unlock(); |
132 | return bRet; | 132 | return bRet; |
133 | } | 133 | } |
134 | 134 | ||
135 | int getSize() | 135 | int getSize() |
136 | { | 136 | { |
137 | imData.lock(); | 137 | imData.lock(); |
138 | int iRet = hData.getSize(); | 138 | int iRet = hData.getSize(); |
139 | imData.unlock(); | 139 | imData.unlock(); |
140 | return iRet; | 140 | return iRet; |
141 | } | 141 | } |
142 | 142 | ||
143 | private: | 143 | private: |
144 | Heap< item, cmpfunc, itemalloc > hData; | 144 | Heap< item, cmpfunc, itemalloc > hData; |
145 | Mutex imData; | 145 | Mutex imData; |
146 | Condition icBlock; | 146 | Condition icBlock; |
147 | }; | 147 | }; |
148 | }; | 148 | }; |
149 | 149 | ||
150 | #endif | 150 | #endif |