Changeset 16730 for trunk/FACT++/src


Ignore:
Timestamp:
06/05/13 21:12:34 (11 years ago)
Author:
tbretz
Message:
Changed the default queue in three ways: 1) Execute() is called after an Event was handled; 2) a conditional variable is used which gets signaled if a new event is pushed; 3) after a maximum inactivity time of 10ms, Execute is called
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r16726 r16730  
    167167    const lock_guard<mutex> guard(fMutex);
    168168    fEventQueue.emplace_back(cmd);
     169    fCond.notify_one();
    169170}
    170171
     
    10081009        SetCurrentState(kSM_Ready, "by Run()");
    10091010
    1010         while (!fExitRequested)
     1011        std::unique_lock<std::mutex> lock(fMutex);
     1012        fMutex.unlock();
     1013
     1014        while (1)
    10111015        {
    1012             usleep(1);
     1016            fMutex.lock();
     1017            if (IsQueueEmpty())
     1018                fCond.wait_for(lock, chrono::microseconds(10000));
     1019            fMutex.unlock();
     1020
     1021            if (fExitRequested)
     1022                break;
     1023
    10131024            if (dummy)
    10141025                continue;
    10151026
     1027            // If the command stack is empty go on with processing in the
     1028            // current state
     1029            if (!IsQueueEmpty())
     1030            {
     1031                // Pop the next command which arrived from the stack
     1032                const shared_ptr<Event> cmd(PopEvent());
     1033                if (!HandleEvent(*cmd))
     1034                    break;
     1035            }
     1036
    10161037            // Execute a step in the current state of the state machine
    10171038            if (!HandleNewState(Execute(), 0, "by Execute-command"))
    1018                 break;
    1019 
    1020             // If the command stack is empty go on with processing in the
    1021             // current state
    1022             if (IsQueueEmpty())
    1023                 continue;
    1024 
    1025             // Pop the next command which arrived from the stack
    1026             const shared_ptr<Event> cmd(PopEvent());
    1027 
    1028             if (!HandleEvent(*cmd))
    10291039                break;
    10301040        }
  • trunk/FACT++/src/StateMachineImp.h

    r16726 r16730  
    77#include <vector>
    88#include <memory>
     9#include <condition_variable>
    910
    1011#include "MainImp.h"
     
    4950    std::mutex fMutexEvt; /// Mutex to ensure thread-safe access to the command fifo
    5051
     52    std::condition_variable fCond; /// Conditional to signal run the an event is waiting
     53
    5154    bool fBufferEvents;  /// Flag if events should be buffered outside the event loop
    5255
Note: See TracChangeset for help on using the changeset viewer.