Changeset 12745 for source/ariba/utility/system
- Timestamp:
- Feb 25, 2014, 1:35:11 PM (11 years ago)
- Location:
- source/ariba/utility/system
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/system/SystemQueue.cpp
r12524 r12745 37 37 38 38 #include "SystemQueue.h" 39 #include <stdexcept> 39 40 40 41 namespace ariba { … … 43 44 use_logging_cpp(SystemQueue); 44 45 46 // /// Singleton 47 // SystemQueue::_inst(NULL); 48 49 45 50 SystemQueue::SystemQueue() 46 51 #ifndef UNDERLAY_OMNET 47 : delayScheduler( &directScheduler ), systemQueueRunning( false ) 52 : delayScheduler( &directScheduler ), 53 systemQueueRunning( false ) 48 54 #endif 49 55 { 50 } 51 52 SystemQueue::~SystemQueue() { 56 logging_info("Creating SystemQueue at: " << this); 57 } 58 59 SystemQueue::~SystemQueue() 60 { 53 61 } 54 62 … … 57 65 { 58 66 static SystemQueue _inst; 59 // std::cout << "SystemQueue::instance: " << &_inst << std::endl;60 67 return _inst; 68 69 // /// create singleton instance 70 // if ( _inst == NULL ) 71 // { 72 // _inst = new SystemQueue(); 73 // 74 // logging_info("Creating SystemQueue at: " << _inst); 75 // } 76 // 77 // return *_inst; 61 78 } 62 79 … … 209 226 boost::mutex::scoped_lock lock( queueMutex ); 210 227 228 if ( delay > 0 ) 229 { 230 logging_debug("SystemQueue(" << this << ") : Schedule event in: " << delay << " ms; Events in queue (before insert): " << eventsQueue.size() ); 231 } 232 211 233 eventsQueue.push_back( event ); 212 234 eventsQueue.back().scheduledTime = boost::posix_time::microsec_clock::local_time(); 213 235 eventsQueue.back().delayTime = delay; 214 236 eventsQueue.back().remainingDelay = delay; 237 238 if ( delay > 0 ) 239 { 240 logging_debug("SystemQueue(" << this << ") : Events in queue (after insert): " << eventsQueue.size() ); 241 } 215 242 216 243 onItemInserted( event ); … … 267 294 // and deliver it to the queue handler 268 295 SystemEvent ev = obj->eventsQueue.front(); 296 297 // XXX debugging the delay-scheduler.. 298 if ( ev.delayTime > 0 ) 299 logging_debug("SystemQueue(" << obj << ") : Events in queue (before execution): " << obj->eventsQueue.size()); 300 269 301 obj->eventsQueue.erase( obj->eventsQueue.begin() ); 270 302 … … 275 307 obj->queueMutex.lock(); 276 308 309 // XXX debugging the delay-scheduler.. 310 if ( ev.delayTime > 0 ) 311 logging_debug("SystemQueue(" << obj << ") : Remaining events in queue (after execution): " << obj->eventsQueue.size()); 312 277 313 } // !obj->eventsQueue.empty() ) 278 314 } // while (obj->running) … … 320 356 void SystemQueue::QueueThreadDelay::onItemInserted( const SystemEvent& event ){ 321 357 322 if( !isSleeping) return; 358 if( !isSleeping) 359 { 360 logging_warn("SystemQueue(" << this << ") : No, I'm not asleep!! New item inserted."); 361 return; // TODO Mario: shouldn't we sort anyway..? 362 } 323 363 324 364 // break an existing sleep and … … 336 376 EventQueue::iterator iend = eventsQueue.end(); 337 377 378 logging_debug("SystemQueue(" << this << ") : Adjusting remaining delays:"); 379 380 // TODO Mario: What about the just inserted event..? 338 381 for( ; i != iend; i++ ) { 339 382 … … 341 384 i->remainingDelay = 0; 342 385 else 386 { 343 387 i->remainingDelay -= sleptTime; 388 389 // XXX Mario: Testcode, just to find a bug... 390 boost::posix_time::time_duration time_passed = sleepEnd - i->getScheduledTime(); 391 logging_debug("SystemQueue(" << this << ") : Total: " << 392 i->delayTime << ", remainingDelay: " << i->remainingDelay << 393 ", time already passed: " << time_passed.total_milliseconds() ); 394 } 344 395 345 396 } // for( ; i != iend; i++ ) … … 372 423 boost::posix_time::milliseconds(event.remainingDelay); 373 424 425 logging_debug("SystemQueue(" << this << ") : Sleeping for: " << event.remainingDelay << " ms"); 426 374 427 { 375 428 boost::unique_lock<boost::mutex> lock( sleepMutex ); … … 377 430 sleepStart = boost::posix_time::microsec_clock::local_time(); 378 431 isSleeping = true; 379 432 380 433 sleepCond.timed_wait( lock, duration ); 381 434 … … 393 446 uint32_t sleptTime = duration.total_milliseconds(); 394 447 448 logging_debug("SystemQueue(" << this << ") : Slept for: " << sleptTime << " ms; until: " << sleepEnd); 449 450 // TODO MARIO: find the bug that loses events... 395 451 if (event.remainingDelay <= sleptTime) 452 { 453 logging_debug("SystemQueue(" << this << ") : Transferring scheduled event into the direct queue. Scheduled time: " << event.getScheduledTime() ); 396 454 transferQueue->insert( event, 0 ); 455 } 456 else 457 { 458 logging_warn("SystemQueue(" << this << ") : Scheduled event lost!! :-( (Sleep should have been " << event.remainingDelay - sleptTime << " ms longer..)"); 459 logging_debug("SystemQueue(" << this << ") : Total delay: " << event.delayTime << "; remaining delay: " << event.remainingDelay); 460 461 // throw std::logic_error("Scheduled event lost!! :-("); 462 } 397 463 } 398 464 -
source/ariba/utility/system/SystemQueue.h
r12524 r12745 223 223 224 224 //******************************************************** 225 226 227 // /// Singleton 228 // static SystemQueue* _inst; 225 229 226 230 QueueThreadDirect directScheduler;
Note:
See TracChangeset
for help on using the changeset viewer.