Changeset 17268 for trunk/Mars


Ignore:
Timestamp:
10/18/13 22:21:27 (11 years ago)
Author:
tbretz
Message:
Implemented a <-operator to allow for sorting and the possibility to request prompt execution.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/mcore/Queue.h

    r17227 r17268  
    2929        kStop,
    3030        kAbort,
    31         kTrigger
     31        kTrigger,
     32        kPrompt
     33
    3234    };
    3335
     
    184186    }
    185187
     188    bool enablePromptExecution()
     189    {
     190        const std::lock_guard<std::mutex> lock(fMutex);
     191        if (fState!=kIdle || fSize>0)
     192            return false;
     193
     194        fState = kPrompt;
     195        return true;
     196    }
     197
     198    bool disablePromptExecution()
     199    {
     200        const std::lock_guard<std::mutex> lock(fMutex);
     201        if (fState!=kPrompt)
     202            return false;
     203
     204        fState = kIdle;
     205        return true;
     206    }
     207
     208    bool setPromptExecution(bool state)
     209    {
     210        return state ? enablePromptExecution() : disablePromptExecution();
     211    }
     212
     213
    186214    bool post(const T &val)
    187215    {
    188216        const std::lock_guard<std::mutex> lock(fMutex);
     217        if (fState==kPrompt)
     218            return fCallback(val);
    189219
    190220        if (fState==kIdle)
     
    216246    {
    217247        const std::lock_guard<std::mutex> lock(fMutex);
     248        if (fState==kPrompt)
     249            return fCallback(T(__args...));
     250
    218251        if (fState==kIdle)
    219252            return false;
     
    261294        return fSize==0;
    262295    }
     296
     297    bool operator<(const Queue& other) const
     298    {
     299        return fSize < other.fSize;
     300    }
     301
    263302};
    264303
Note: See TracChangeset for help on using the changeset viewer.