Ignore:
Timestamp:
06/08/12 17:09:54 (12 years ago)
Author:
tbretz
Message:
Added locking to subscription and unsubscription of events. This doesn't happen often, so it shouldn't harm. The advantage is that subsccriptions can happen even if there are still afew events in the queue. Note that the constructor is not locked, so it must be ensured that no Subscriptions or Unssubscriptions happen during the construction.
File:
1 edited

Legend:

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

    r14008 r14124  
    4141    std::queue<Event*>     fEventQueue;   /// Event queue (fifo) for the received commands
    4242
    43     std::mutex fMutex;   /// Mutex to ensure thread-safe access to the command fifo
     43    std::mutex fMutex;    /// Mutex to ensure thread-safe access to the command fifo
     44    std::mutex fMutexEvt; /// Mutex to ensure thread-safe access to the command fifo
    4445
    4546    bool fRunning;       /// Machine is in main-loop
     
    101102
    102103    EventImp &Subscribe(const std::string &name);
     104    void Unsubscribe(EventImp *evt);
    103105
    104106    /// return the current state of the machine
     
    128130
    129131    // Event handling
    130     bool HasEvent(const EventImp *cmd) const;
    131     EventImp *FindEvent(const std::string &evt) const;
     132    bool HasEvent(const EventImp *cmd);
     133    EventImp *FindEvent(const std::string &evt);
    132134
    133135    bool IsQueueEmpty() const { return fEventQueue.size()==0; }
    134136
    135     const std::vector<EventImp*> &GetListOfEvents() const { return fListOfEvents; }
    136     const std::vector<std::string> GetEventNames() const;
    137 
    138     void PrintListOfEvents(std::ostream &out, const std::string &evt="") const;
    139     void PrintListOfEvents(const std::string &str="") const;
    140 
    141     void PrintListOfAllowedEvents(std::ostream &out) const;
    142     void PrintListOfAllowedEvents() const;
     137    //const std::vector<EventImp*> &GetListOfEvents() const { return fListOfEvents; }
     138    const std::vector<std::string> GetEventNames();
     139
     140    void PrintListOfEvents(std::ostream &out, const std::string &evt="");
     141    void PrintListOfEvents(const std::string &str="");
     142
     143    void PrintListOfAllowedEvents(std::ostream &out);
     144    void PrintListOfAllowedEvents();
    143145
    144146    void PrintListOfStates(std::ostream &out) const;
Note: See TracChangeset for help on using the changeset viewer.