Changeset 14567 for trunk/FACT++


Ignore:
Timestamp:
11/06/12 00:23:11 (12 years ago)
Author:
tbretz
Message:
Fixed a problem with the mutics. If an event is unsubscribed, it can call the infoHandler to signal that it is disconnected, which would call HasEvent, which uses the samemutex than Unsubscribe
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/StateMachineImp.cc

    r14558 r14567  
    177177void StateMachineImp::PushEvent(Event *cmd)
    178178{
    179     fMutex.lock();
     179    const lock_guard<mutex> guard(fMutex);
    180180    fEventQueue.push(cmd);
    181     fMutex.unlock();
    182181}
    183182
     
    193192Event *StateMachineImp::PopEvent()
    194193{
    195     fMutex.lock();
     194    const lock_guard<mutex> guard(fMutex);
    196195
    197196    // Get the next event from the stack
     
    199198    Event *cmd = fEventQueue.front();
    200199    fEventQueue.pop();
    201 
    202     fMutex.unlock();
    203200
    204201    return cmd;
     
    554551#endif
    555552
    556     fMutexEvt.lock();
     553    const lock_guard<mutex> guard(fMutexEvt);
    557554    fListOfEvents.push_back(evt);
    558     fMutexEvt.unlock();
    559 
    560555    return *evt;
    561556}
     
    622617    EventImp *evt = CreateService(name);
    623618
    624     fMutexEvt.lock();
     619    const lock_guard<mutex> guard(fMutexEvt);
    625620    fListOfEvents.push_back(evt);
    626     fMutexEvt.unlock();
    627 
    628621    return *evt;
    629622}
     
    631624void StateMachineImp::Unsubscribe(EventImp *evt)
    632625{
    633     const lock_guard<mutex> guard(fMutexEvt);
    634 
    635     auto it = find(fListOfEvents.begin(), fListOfEvents.end(), evt);
    636     if (it==fListOfEvents.end())
     626    {
     627        const lock_guard<mutex> guard(fMutexEvt);
     628
     629        auto it = find(fListOfEvents.begin(), fListOfEvents.end(), evt);
     630        if (it==fListOfEvents.end())
    637631        return;
    638632
    639     fListOfEvents.erase(it);
     633        fListOfEvents.erase(it);
     634    }
    640635    delete evt;
    641636}
Note: See TracChangeset for help on using the changeset viewer.