Changeset 16089 for trunk/FACT++


Ignore:
Timestamp:
05/23/13 19:09:19 (12 years ago)
Author:
tbretz
Message:
Use empty() instead of size() where possible; replaced queues by list where possible
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r16073 r16089  
    137137    for (vector<EventImp*>::iterator cmd=fListOfEvents.begin(); cmd!=fListOfEvents.end(); cmd++)
    138138        delete *cmd;
    139 
    140     // Unfortunately, front() doesn't necessarily return 0 if
    141     // queue is empty
    142     while (fEventQueue.size())
    143     {
    144         Event *q=fEventQueue.front();
    145         if (!q)
    146             break;
    147 
    148         fEventQueue.pop();
    149         delete q;
    150     }
    151139}
    152140
     
    178166{
    179167    const lock_guard<mutex> guard(fMutex);
    180     fEventQueue.push(cmd);
     168    fEventQueue.push_back(shared_ptr<Event>(cmd));
    181169}
    182170
     
    190178//!    A pointer to an Event object
    191179//
    192 Event *StateMachineImp::PopEvent()
     180shared_ptr<Event> StateMachineImp::PopEvent()
    193181{
    194182    const lock_guard<mutex> guard(fMutex);
     
    196184    // Get the next event from the stack
    197185    // 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();
    201188    return cmd;
    202189}
     
    10371024
    10381025            // Pop the next command which arrived from the stack
    1039             const auto_ptr<Event> cmd(PopEvent());
     1026            const shared_ptr<Event> cmd(PopEvent());
    10401027
    10411028            if (!HandleEvent(*cmd))
  • trunk/FACT++/src/StateMachineImp.h

    r14558 r16089  
    33
    44#include <map>
    5 #include <queue>
     5#include <list>
    66#include <mutex>
    77#include <vector>
     8#include <memory>
    89
    910#include "MainImp.h"
     
    4344private:
    4445    std::vector<EventImp*> fListOfEvents; /// List of available commands as setup by user
    45     std::queue<Event*>    fEventQueue;   /// Event queue (fifo) for the received commands
     46    std::list<std::shared_ptr<Event>> fEventQueue;   /// Event queue (fifo) for the received commands
    4647
    4748    std::mutex fMutex;    /// Mutex to ensure thread-safe access to the command fifo
     
    5455    /// Push a command into the fifo. The fifo takes over ownership
    5556    void PushEvent(Event *cmd);
    56     /// Pop a command from the fifo. You take over owenership
    57     Event *PopEvent();
     57    /// Pop a command from the fifo.
     58    std::shared_ptr<Event> PopEvent();
    5859
    5960    bool HandleNewState(int newstate, const EventImp *evt, const char *txt);
     
    137138    EventImp *FindEvent(const std::string &evt);
    138139
    139     bool IsQueueEmpty() const { return fEventQueue.size()==0; }
     140    bool IsQueueEmpty() const { return fEventQueue.empty(); }
    140141
    141142    //const std::vector<EventImp*> &GetListOfEvents() const { return fListOfEvents; }
Note: See TracChangeset for help on using the changeset viewer.