Changeset 12762 for source/ariba/utility/system
- Timestamp:
- Mar 12, 2014, 6:58:54 PM (11 years ago)
- Location:
- source/ariba/utility/system
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/system/SystemQueue.cpp
r12761 r12762 43 43 namespace utility { 44 44 45 typedef boost::mutex::scoped_lock scoped_lock; 45 46 46 47 using boost::posix_time::microsec_clock; 47 48 using boost::posix_time::time_duration; 48 // using boost::mutex::scoped_lock;49 typedef boost::mutex::scoped_lock scoped_lock;50 49 using boost::date_time::not_a_date_time; 51 50 using boost::scoped_ptr; … … 54 53 use_logging_cpp(SystemQueue); 55 54 56 SystemQueue::SystemQueue() 57 { 58 logging_info("Creating SystemQueue at: " << this); 55 SystemQueue::SystemQueue() : 56 SysQ( new QueueThread() ) 57 { 58 logging_debug("Creating SystemQueue at: " << this); 59 59 } 60 60 … … 76 76 SystemEvent ev(event); 77 77 78 SysQ .insert(ev, delay);78 SysQ->insert(ev, delay); 79 79 } 80 80 … … 95 95 void SystemQueue::run() 96 96 { 97 assert ( ! SysQ .running );98 99 SysQ .running = true;97 assert ( ! SysQ->running ); 98 99 SysQ->running = true; 100 100 101 101 // start thread 102 sysq_thread.reset( new boost::thread(boost::ref( SysQ)) );102 sysq_thread.reset( new boost::thread(boost::ref(*SysQ)) ); 103 103 } 104 104 … … 106 106 { 107 107 // signal SysQ to quit (and abort queued events) 108 SysQ .cancel();108 SysQ->cancel(); 109 109 110 110 // wait till actually completes 111 111 // (should be fast, but the current event is allowed to finish) 112 logging_ info("/// joining system queuethread");112 logging_debug("/// ... joining SysQ thread"); 113 113 sysq_thread->join(); 114 114 … … 116 116 sysq_thread.reset(); 117 117 118 assert ( ! SysQ .isRunning() );119 120 121 // TODO FIXME gtest reuses the singleton... :-/122 // maybe delete the SysQ object here..? (scoped_ptr...)123 SysQ. aborted = false; // XXX hotfix..118 assert ( ! SysQ->isRunning() ); 119 120 121 // clean up and respawn 122 logging_debug("/// respawning SysQ"); 123 SysQ.reset( new QueueThread() ); 124 124 } 125 125 … … 133 133 bool SystemQueue::isEmpty() 134 134 { 135 // XXX 136 // return directScheduler.isEmpty() || delayScheduler.isEmpty(); 137 138 return true; 135 return SysQ->isEmpty(); 139 136 } 140 137 141 138 bool SystemQueue::isRunning() 142 139 { 143 return SysQ .isRunning();140 return SysQ->isRunning(); 144 141 } 145 142 … … 159 156 now( not_a_date_time ), 160 157 next_deadline( not_a_date_time ), 158 processing_event( false ), 161 159 running( false ), 162 160 aborted( false ) … … 170 168 void SystemQueue::QueueThread::operator()() 171 169 { 172 // XXX debug 173 logging_info( "/// SysQ thread is alive." ); 170 logging_debug( "/// SysQ thread is alive." ); 174 171 175 172 assert( running ); // this is set before the thread starts … … 188 185 } 189 186 190 // XXX debug 191 logging_info( "/// SysQ thread is quitting." ); 187 logging_debug( "/// SysQ thread is quitting." ); 192 188 193 189 running = false; … … 213 209 { 214 210 scoped_lock lock( queue_mutex ); 211 212 this->processing_event = true; 215 213 216 214 // dequeue first event … … 219 217 } 220 218 221 // XXX debug 222 logging_info("/// SysQ: dispatching event"); 219 logging_debug("/// SysQ: dispatching event"); 223 220 224 221 currently_processed_event->getListener()->handleSystemEvent( *currently_processed_event ); … … 228 225 now = get_clock(); // NOTE: this is reused in check_timed_queue(); 229 226 time_duration execution_time = now - start_time; 227 228 this->processing_event = false; 230 229 231 230 // DEBUG OUTPUT: warning when execution takes too much time … … 233 232 if ( execution_time.total_milliseconds() > 50 ) 234 233 { 235 logging_ debug("WARNING: Last event took " << execution_time.total_milliseconds() << " to complete.");234 logging_info("WARNING: Last event took " << execution_time.total_milliseconds() << " to complete."); 236 235 } 237 236 } … … 290 289 if ( this->next_deadline.is_not_a_date_time() ) 291 290 { 292 // XXX debug output 293 logging_info("/// SysQ is going to sleep (forever..)."); 291 logging_debug("/// SysQ is going to sleep."); 294 292 295 293 this->system_queue_idle.wait( lock ); … … 298 296 else 299 297 { 300 // XXX debug output301 time_duration sleep_time = next_deadline - get_clock();302 logging_info("/// SysQ is going to sleep for " << sleep_time.total_milliseconds()<< "ms.");298 logging_debug("/// SysQ is going to sleep for " 299 << ( next_deadline - get_clock() ).total_milliseconds() 300 << "ms."); 303 301 304 302 this->system_queue_idle.timed_wait( lock, next_deadline ); … … 326 324 void SystemQueue::QueueThread::cancel() 327 325 { 328 logging_debug("/// cancelling system queue");326 logging_debug("/// Cancelling system queue... "); 329 327 330 328 // SYNCHRONIZED … … 334 332 } 335 333 336 // XXX debug output 337 logging_info("/// SysQ: " << immediateEventsQ.size() << " immediate event(s) + " 334 logging_debug("/// SysQ: " << immediateEventsQ.size() << " immediate event(s) + " 338 335 << timedEventsQ.size() << " timed event(s) left."); 339 336 … … 360 357 system_queue_idle.notify_one(); // NOTE: there is only one thread 361 358 // (so it doesn't matter whether to call notify_one, or notify_all) 359 } 360 361 362 bool SystemQueue::QueueThread::isEmpty() 363 { 364 // SYNCHRONIZED 365 scoped_lock lock( queue_mutex ); 366 367 return immediateEventsQ.empty() && timedEventsQ.empty() && ! processing_event; 362 368 } 363 369 -
source/ariba/utility/system/SystemQueue.h
r12761 r12762 206 206 EventQueue immediateEventsQ; 207 207 EventQueue timedEventsQ; 208 // boost::mutex queueMutex;209 210 // SystemEvent& currently_processed_event;211 208 212 209 ptime now; … … 215 212 boost::condition_variable system_queue_idle; 216 213 boost::mutex queue_mutex; 217 218 // boost::condition_variable itemsAvailable; DEPRECATED 214 215 bool processing_event; 216 219 217 volatile bool running; 220 218 volatile bool aborted; … … 244 242 /// member variables of class SystemQueue 245 243 private: 246 QueueThreadSysQ;244 boost::scoped_ptr<QueueThread> SysQ; 247 245 boost::scoped_ptr<boost::thread> sysq_thread; 248 246
Note:
See TracChangeset
for help on using the changeset viewer.