Changeset 4483 for source/ariba/utility
- Timestamp:
- Jun 25, 2009, 11:06:52 AM (15 years ago)
- Location:
- source/ariba/utility/system
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
source/ariba/utility/system/StartupWrapper.cpp
r4462 r4483 48 48 49 49 SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup"); 50 SystemEventType StartupWrapperEventShutdown("StartupWrapperEventShutdown");51 50 52 51 StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){ … … 73 72 #endif 74 73 75 void StartupWrapper::initSystem(){ 76 77 static bool initialized = false; 78 if( initialized ) return; 79 initialized = true; 74 void StartupWrapper::startSystem(){ 80 75 81 76 // … … 121 116 } 122 117 118 void StartupWrapper::stopSystem(){ 119 SystemQueue::instance().cancel(); 120 } 121 123 122 void StartupWrapper::initConfig(string filename){ 124 123 configurations.push( filename ); … … 142 141 143 142 service->startup(); 144 145 } else if( event.getType() == StartupWrapperEventShutdown ){146 147 service->shutdown();148 SystemQueue::instance().cancel();149 143 150 144 } … … 174 168 175 169 if(block){ 176 SystemEvent ev (service->wrapper, StartupWrapperEventShutdown); 177 service->wrapper->handleSystemEvent(ev); 178 170 // call directly 171 service->shutdown(); 179 172 }else{ 180 SystemQueue::instance().scheduleEvent( 181 SystemEvent( service->wrapper, StartupWrapperEventShutdown, NULL), 0 ); 173 // call async, but not using systemqueue! // TODO: mem leak 174 AsyncShutdown* async = new AsyncShutdown(service); 175 async->runBlockingMethod(); 182 176 } 183 177 } 184 178 179 StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service) 180 : service(_service){ 181 } 182 183 void StartupWrapper::AsyncShutdown::blockingFunction(){ 184 service->shutdown(); 185 } 186 187 void StartupWrapper::AsyncShutdown::dispatchFunction(){ 188 //unused 189 } 190 185 191 }} // namespace ariba, utility -
source/ariba/utility/system/StartupWrapper.h
r4462 r4483 44 44 #include "SystemQueue.h" 45 45 #include "StartupInterface.h" 46 #include "../configuration/Configuration.h" 46 #include "ariba/utility/configuration/Configuration.h" 47 #include "BlockingMethod.h" 47 48 48 49 #ifdef UNDERLAY_OMNET … … 69 70 class StartupWrapper : public SystemEventListener { 70 71 public: 71 static void initSystem(); 72 static void startSystem(); 73 static void stopSystem(); 74 72 75 static void initConfig(string filename); 73 76 static void startup(StartupInterface* service, bool block = true); … … 96 99 void waitForExit(); 97 100 StartupInterface* service; 101 102 class AsyncShutdown : public BlockingMethod { 103 public: 104 AsyncShutdown(StartupInterface* _service); 105 protected: 106 virtual void dispatchFunction(); 107 virtual void blockingFunction(); // unused 108 private: 109 StartupInterface* service; 110 }; 111 98 112 }; 99 113 -
source/ariba/utility/system/SystemQueue.cpp
r3690 r4483 130 130 131 131 // cause the thread to exit 132 running = false; 133 itemsAvailable.notify_all(); 132 { 133 boost::mutex::scoped_lock lock(queueMutex); 134 running = false; 135 136 while( eventsQueue.size() > 0 ){ 137 eventsQueue.erase( eventsQueue.begin() ); 138 } 139 140 itemsAvailable.notify_all(); 141 } 134 142 135 143 // wait that the thread has exited … … 139 147 delete queueThread; 140 148 queueThread = NULL; 141 142 while( eventsQueue.size() > 0 ){143 eventsQueue.erase( eventsQueue.begin() );144 }145 149 } 146 150 … … 151 155 152 156 void SystemQueue::QueueThread::insert( const SystemEvent& event, uint32_t delay ){ 153 { 154 boost::mutex::scoped_lock lock( queueMutex ); 155 156 eventsQueue.push_back( event ); 157 eventsQueue.back().scheduledTime = boost::posix_time::microsec_clock::local_time(); 158 eventsQueue.back().delayTime = delay; 159 eventsQueue.back().remainingDelay = delay; 160 161 onItemInserted( event ); 162 itemsAvailable.notify_all(); 163 } 157 158 // if this is called from a module that is currently handling 159 // a thread (called from SystemQueue::onNextQueueItem), the 160 // thread is the same anyway and the mutex will be already 161 // aquired, otherwise we aquire it now 162 163 boost::mutex::scoped_lock lock( queueMutex ); 164 165 eventsQueue.push_back( event ); 166 eventsQueue.back().scheduledTime = boost::posix_time::microsec_clock::local_time(); 167 eventsQueue.back().delayTime = delay; 168 eventsQueue.back().remainingDelay = delay; 169 170 onItemInserted( event ); 171 itemsAvailable.notify_all(); 164 172 } 165 173 … … 177 185 while ( obj->eventsQueue.empty() && obj->running ){ 178 186 179 const boost::system_time duration =180 boost::get_system_time() +181 boost::posix_time::milliseconds(40);187 // const boost::system_time duration = 188 // boost::get_system_time() + 189 // boost::posix_time::milliseconds(100); 182 190 183 191 obj->itemsAvailable.wait( lock ); … … 185 193 } 186 194 195 // 187 196 // work all the items that are currently in the queue 188 189 while( !obj->eventsQueue.empty() ) { 190 191 // fetch the first item in the queue and deliver it to the 192 // queue handler 197 // 198 199 while( !obj->eventsQueue.empty() && obj->running ) { 200 201 // fetch the first item in the queue 202 // and deliver it to the queue handler 193 203 SystemEvent ev = obj->eventsQueue.front(); 194 204 obj->eventsQueue.erase( obj->eventsQueue.begin() ); 195 205 196 { 197 // unlock the queue to that an event handler 198 // can insert new items into the queue 199 // obj->queueMutex.unlock(); 200 obj->onNextQueueItem( ev ); 201 // obj->queueMutex.lock(); 202 } 206 // call the queue and this will 207 // call the actual event handler 208 obj->onNextQueueItem( ev ); 203 209 204 210 } // !obj->eventsQueue.empty() ) 205 211 } // while (obj->running) 212 213 logging_debug("system queue exited"); 206 214 } 207 215
Note:
See TracChangeset
for help on using the changeset viewer.