Ignore:
Timestamp:
06/09/13 12:51:13 (11 years ago)
Author:
tbretz
Message:
A less CPU hungry version of the msg queue using C++11 techniques.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosy/base/msgqueue.h

    r8843 r16779  
    22#define COSY_MsgQueue
    33
    4 #ifndef ROOT_TMutex
    5 #include <TMutex.h>
    6 #endif
    7 
    8 #ifndef MARS_MThread
    9 #include "MThread.h"
     4#ifndef __CINT__
     5#include <list>
     6#include <mutex>
     7#include <thread>
     8#include <vector>
     9#include <condition_variable>
    1010#endif
    1111
     
    1313#define WM_QUIT 0xffff
    1414
    15 class MsgQueue : public MThread
     15class MsgQueue
    1616{
    1717private:
    18     int    fNextMsg;
    19     char  *fNextPtr;
     18    size_t fSize;                 // Only necessary for before C++11
    2019
    21     TMutex fMuxMsg;
     20#ifndef __CINT__
     21    std::list<std::pair<int, std::vector<char>>> fList;
    2222
    23     Int_t Thread();
     23    std::mutex fMutex;        // Mutex needed for the conditional
     24    std::condition_variable fCond; // Conditional
     25#endif
     26
     27    enum state_t
     28    {
     29        kIdle,
     30        kRun,
     31        kStop,
     32        kAbort,
     33    };
     34
     35    state_t fState;               // Stop signal for the thread
     36#ifndef __CINT__
     37    std::thread fThread;      // Handle to the thread
     38#endif
     39
     40    void Thread();
    2441
    2542public:
     
    2946    int Break() const;
    3047
    31     virtual Int_t Proc(int msg, void *mp1);
    32     Int_t Proc(int msg) { return Proc(msg, 0); }
     48    void CancelThread();
     49
     50    virtual int Proc(int msg, void *mp1);
     51    int Proc(int msg) { return Proc(msg, 0); }
    3352
    3453    void *PostMsg(int msg, void *mp1, int size);
Note: See TracChangeset for help on using the changeset viewer.