Changeset 12765
- Timestamp:
- Mar 14, 2014, 8:26:33 PM (11 years ago)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/system/SystemQueue.cpp
r12764 r12765 76 76 void SystemQueue::scheduleEvent( const SystemEvent& event, uint32_t delay ) 77 77 { 78 assert ( SysQ->running ); // should we really enforce this? 78 // assert ( SysQ->running ); // should we really enforce this? 79 if ( ! SysQ->running ) 80 { 81 logging_debug("/// WARNING: The SystemQueue is NOT RUNNING!"); 82 } 79 83 80 84 // copy … … 140 144 SysQ.reset( new QueueThread() ); 141 145 } 146 147 148 void SystemQueue::leave() 149 { 150 // signal SysQ to quit (and abort queued events) 151 SysQ->cancel(); 152 } 153 154 void SystemQueue::join() 155 { 156 if ( sysq_thread ) 157 { 158 logging_debug("/// ... joining SysQ thread"); 159 sysq_thread->join(); 160 } 161 } 162 163 142 164 143 165 void SystemQueue::dropAll( const SystemEventListener* mlistener) … … 303 325 if ( timedEventsQ.empty() ) 304 326 { 305 logging_debug("/// SysQ is going to sleep.");327 // logging_debug("/// SysQ is going to sleep."); 306 328 307 329 this->system_queue_idle.wait( lock ); … … 310 332 else 311 333 { 312 logging_debug( "/// SysQ is going to sleep for "313 << ( timedEventsQ.top().deadline - get_clock() ).total_milliseconds()314 << "ms. Deadline: "315 << timedEventsQ.top().deadline316 << ", Clock: "317 << get_clock() );334 // logging_debug( "/// SysQ is going to sleep for " 335 // << ( timedEventsQ.top().deadline - get_clock() ).total_milliseconds() 336 // << "ms. Deadline: " 337 // << timedEventsQ.top().deadline 338 // << ", Clock: " 339 // << get_clock() ); 318 340 319 341 this->system_queue_idle.timed_wait( lock, timedEventsQ.top().deadline ); -
source/ariba/utility/system/SystemQueue.h
r12764 r12765 117 117 * Cancels the system queue and ends the processing after the 118 118 * currently processed event is processed. 119 * 120 * NOTE: Do not call this function from within a SystemQueue-Event. 121 * Use SystemQueue::leave() instead. 119 122 * 120 123 * This method is thread-safe. 121 124 */ 122 125 void cancel(); 126 127 /** 128 * Like SystemQueue::cancel(), but may only be called from within a SystemQueue-Event. 129 * 130 * NOTE: In this case some cleanup can not be made. -- If the SystemQueue is 131 * restarted, SystemQueue::cancel() must be called before SystemQueue::run() 132 * can be called again. 133 */ 134 void leave(); 135 136 /** 137 * Join the SystemQueue thread -- the current thread is blocked until the 138 * SystemQueue finishes. 139 * 140 * NOTE: Use this only in combination with SystemQueue::leave() 141 * 142 * [ There is a possible race condition with SystemQueue::cancel(), but 143 * SystemQueue::join() should not be used at the same time as 144 * SystemQueue::cancel() anyway. (SystemQueue::leave() is fine, though.) 145 */ 146 void join(); 123 147 124 148 /** -
tests/SystemQueue-tests.cc
r12764 r12765 102 102 103 103 checkmark = true; 104 } 105 106 void Leave() 107 { 108 // let's do something before leaving.. 109 this->LongRunner(); 110 checkmark = false; 111 112 cout << "### Leaving SysQ ### "<< endl; 113 SystemQueue::instance().leave(); 104 114 } 105 115 … … 223 233 224 234 /** 235 * leaves the SystemQueue from inside a scheduled event (in contrast to cancel) 236 * 237 * NOTE: due to the SystemQueue singleton design, explicit cleanup is necessary! 238 * 239 * [ NOTE: the old System Queue does not support this. ] 240 */ 241 TEST_F(SystemQueueTest, LeaveFromInsideEvent) 242 { 243 SystemQueue& sysq = SystemQueue::instance(); 244 245 // start 246 sysq.run(); 247 248 // scheduleCall 249 sysq.scheduleCall( 250 boost::bind(&SystemQueueTest::Leave, this) 251 ); 252 253 // schedule another which must NOT be performed 254 sysq.scheduleCall( 255 boost::bind(&SystemQueueTest::Check, this) 256 ); 257 258 // sleep until the SystemQueue thread has finished 259 sysq.join(); 260 261 EXPECT_FALSE( sysq.isRunning() ); 262 263 // ensure Check() was not perfomed 264 EXPECT_FALSE( sysq.isEmpty() ); 265 EXPECT_FALSE( checkmark ); 266 267 // CLEANUP 268 sysq.cancel(); 269 270 EXPECT_FALSE( sysq.isRunning() ); 271 EXPECT_TRUE( sysq.isEmpty() ); 272 } 273 274 275 /** 225 276 * schedule a call and test whether it is actually performed by the SystemQueue 226 277 */
Note:
See TracChangeset
for help on using the changeset viewer.