Changeset 4483


Ignore:
Timestamp:
Jun 25, 2009, 11:06:52 AM (15 years ago)
Author:
Christoph Mayer
Message:

-StartupWrapper bisschen umgeschrieben, erste Schritte für sauberes runterfahren

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sample/pingpong/main.cpp

    r4462 r4483  
    1414
    1515        StartupWrapper::initConfig( config );
    16         StartupWrapper::initSystem();
     16        StartupWrapper::startSystem();
    1717
    1818        // this will do the main functionality and block
     
    2323
    2424        StartupWrapper::shutdown(&ping);
     25        StartupWrapper::stopSystem();
     26
    2527        return 0;
    2628}
  • source/ariba/overlay/BaseOverlay.cpp

    r3718 r4483  
    9999        bc->unregisterMessageReceiver( this );
    100100        bc->unregisterEventListener( this );
     101
     102        if(overlayInterface != NULL){
     103                delete overlayInterface;
     104                overlayInterface = NULL;
     105        }
    101106}
    102107
  • source/ariba/utility/system/StartupWrapper.cpp

    r4462 r4483  
    4848
    4949SystemEventType StartupWrapperEventStartup("StartupWrapperEventStartup");
    50 SystemEventType StartupWrapperEventShutdown("StartupWrapperEventShutdown");
    5150
    5251StartupWrapper::StartupWrapper(StartupInterface* _service) : service( _service ){
     
    7372#endif
    7473
    75 void StartupWrapper::initSystem(){
    76 
    77         static bool initialized = false;
    78         if( initialized ) return;
    79         initialized = true;
     74void StartupWrapper::startSystem(){
    8075
    8176        //
     
    121116}
    122117
     118void StartupWrapper::stopSystem(){
     119        SystemQueue::instance().cancel();
     120}
     121
    123122void StartupWrapper::initConfig(string filename){
    124123        configurations.push( filename );
     
    142141
    143142                service->startup();
    144 
    145         } else if( event.getType() == StartupWrapperEventShutdown ){
    146 
    147                 service->shutdown();
    148                 SystemQueue::instance().cancel();
    149143
    150144        }
     
    174168
    175169        if(block){
    176                 SystemEvent ev (service->wrapper, StartupWrapperEventShutdown);
    177                 service->wrapper->handleSystemEvent(ev);
    178 
     170                // call directly
     171                service->shutdown();
    179172        }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();
    182176        }
    183177}
    184178
     179StartupWrapper::AsyncShutdown::AsyncShutdown(StartupInterface* _service)
     180        : service(_service){
     181}
     182
     183void StartupWrapper::AsyncShutdown::blockingFunction(){
     184        service->shutdown();
     185}
     186
     187void StartupWrapper::AsyncShutdown::dispatchFunction(){
     188        //unused
     189}
     190
    185191}} // namespace ariba, utility
  • source/ariba/utility/system/StartupWrapper.h

    r4462 r4483  
    4444#include "SystemQueue.h"
    4545#include "StartupInterface.h"
    46 #include "../configuration/Configuration.h"
     46#include "ariba/utility/configuration/Configuration.h"
     47#include "BlockingMethod.h"
    4748
    4849#ifdef UNDERLAY_OMNET
     
    6970class StartupWrapper : public SystemEventListener {
    7071public:
    71         static void initSystem();
     72        static void startSystem();
     73        static void stopSystem();
     74
    7275        static void initConfig(string filename);
    7376        static void startup(StartupInterface* service, bool block = true);
     
    9699        void waitForExit();
    97100        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
    98112};
    99113
  • source/ariba/utility/system/SystemQueue.cpp

    r3690 r4483  
    130130
    131131        // 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        }
    134142
    135143        // wait that the thread has exited
     
    139147        delete queueThread;
    140148        queueThread = NULL;
    141 
    142         while( eventsQueue.size() > 0 ){
    143                 eventsQueue.erase( eventsQueue.begin() );
    144         }
    145149}
    146150
     
    151155
    152156void 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();
    164172}
    165173
     
    177185                while ( obj->eventsQueue.empty() && obj->running ){
    178186
    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);
    182190
    183191                        obj->itemsAvailable.wait( lock );
     
    185193                }
    186194
     195                //
    187196                // 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
    193203                        SystemEvent ev = obj->eventsQueue.front();
    194204                        obj->eventsQueue.erase( obj->eventsQueue.begin() );
    195205
    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 );
    203209
    204210                } // !obj->eventsQueue.empty() )
    205211        } // while (obj->running)
     212
     213        logging_debug("system queue exited");
    206214}
    207215
Note: See TracChangeset for help on using the changeset viewer.