Changeset 16089 for trunk/FACT++
- Timestamp:
- 05/23/13 19:09:19 (12 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/StateMachineImp.cc
r16073 r16089 137 137 for (vector<EventImp*>::iterator cmd=fListOfEvents.begin(); cmd!=fListOfEvents.end(); cmd++) 138 138 delete *cmd; 139 140 // Unfortunately, front() doesn't necessarily return 0 if141 // queue is empty142 while (fEventQueue.size())143 {144 Event *q=fEventQueue.front();145 if (!q)146 break;147 148 fEventQueue.pop();149 delete q;150 }151 139 } 152 140 … … 178 166 { 179 167 const lock_guard<mutex> guard(fMutex); 180 fEventQueue.push (cmd);168 fEventQueue.push_back(shared_ptr<Event>(cmd)); 181 169 } 182 170 … … 190 178 //! A pointer to an Event object 191 179 // 192 Event *StateMachineImp::PopEvent()180 shared_ptr<Event> StateMachineImp::PopEvent() 193 181 { 194 182 const lock_guard<mutex> guard(fMutex); … … 196 184 // Get the next event from the stack 197 185 // and remove event from the stack 198 Event *cmd = fEventQueue.front(); 199 fEventQueue.pop(); 200 186 const shared_ptr<Event> cmd = fEventQueue.front(); 187 fEventQueue.pop_front(); 201 188 return cmd; 202 189 } … … 1037 1024 1038 1025 // Pop the next command which arrived from the stack 1039 const auto_ptr<Event> cmd(PopEvent());1026 const shared_ptr<Event> cmd(PopEvent()); 1040 1027 1041 1028 if (!HandleEvent(*cmd)) -
trunk/FACT++/src/StateMachineImp.h
r14558 r16089 3 3 4 4 #include <map> 5 #include < queue>5 #include <list> 6 6 #include <mutex> 7 7 #include <vector> 8 #include <memory> 8 9 9 10 #include "MainImp.h" … … 43 44 private: 44 45 std::vector<EventImp*> fListOfEvents; /// List of available commands as setup by user 45 std:: queue<Event*>fEventQueue; /// Event queue (fifo) for the received commands46 std::list<std::shared_ptr<Event>> fEventQueue; /// Event queue (fifo) for the received commands 46 47 47 48 std::mutex fMutex; /// Mutex to ensure thread-safe access to the command fifo … … 54 55 /// Push a command into the fifo. The fifo takes over ownership 55 56 void PushEvent(Event *cmd); 56 /// Pop a command from the fifo. You take over owenership57 Event *PopEvent();57 /// Pop a command from the fifo. 58 std::shared_ptr<Event> PopEvent(); 58 59 59 60 bool HandleNewState(int newstate, const EventImp *evt, const char *txt); … … 137 138 EventImp *FindEvent(const std::string &evt); 138 139 139 bool IsQueueEmpty() const { return fEventQueue. size()==0; }140 bool IsQueueEmpty() const { return fEventQueue.empty(); } 140 141 141 142 //const std::vector<EventImp*> &GetListOfEvents() const { return fListOfEvents; }
Note:
See TracChangeset
for help on using the changeset viewer.