WSF
WsfThread.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFTHREAD_HPP
13#define WSFTHREAD_HPP
14
15#include "wsf_export.h"
16
17#include <condition_variable>
18#include <mutex>
19
20#include "UtThread.hpp"
21
22class WSF_EXPORT WsfThread : public UtThread
23{
24public:
26 {
30 PAUSED = 3,
32 };
33
34 WsfThread() = default;
35 ~WsfThread() override = default;
36
37 void Run() override;
38
39 FunctionType GetFunction() const { return mFunction; }
40
42
43 bool CriticalWork() const { return (mFunction == CRITICAL); }
44 bool ReadyForWork() const { return (mFunction == AVAILABLE); }
45 bool Stopped() const { return (mFunction == STOPPED); }
47
51 bool ForceStopWork(); // attempts to stop thread, even if not available
52 bool PauseWork();
54
58 void EndThread();
59
60 void WaitUntilWorkDone();
61 bool TryWaitUntilWorkDone(double aTimeoutSecs);
63
64
71 virtual void Available();
72
78 virtual FunctionType DoWork() = 0;
79
85 virtual FunctionType Pause() = 0;
87
88protected:
89 bool BeginCriticalWork();
90 bool EndCriticalWork();
91
93
94 bool SetFunction(FunctionType aOldFunction, FunctionType aNewFunction);
95
96 std::condition_variable mWorkDoneCond;
98
99private:
100 std::condition_variable mWorkAddedCond;
101
105 FunctionType mFunction = AVAILABLE;
106
109 bool mEndThread = false;
110};
111
112#endif // WSFTHREAD_HPP
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
virtual FunctionType Pause()=0
bool AssignWork()
Thread internal Run() control methods.
Definition WsfThread.hpp:49
std::mutex mFunctionWriteMutex
Definition WsfThread.hpp:97
std::condition_variable mWorkDoneCond
Definition WsfThread.hpp:96
~WsfThread() override=default
WsfThread()=default
void Run() override
Definition WsfThread.cpp:26
bool StopWork()
Definition WsfThread.hpp:50
bool EndCriticalWork()
Definition WsfThread.cpp:128
bool Stopped() const
Definition WsfThread.hpp:45
virtual FunctionType DoWork()=0
bool CriticalWork() const
Thread Run() function status methods.
Definition WsfThread.hpp:43
FunctionType mSavedState
Definition WsfThread.hpp:92
FunctionType GetFunction() const
Definition WsfThread.hpp:39
FunctionType
Definition WsfThread.hpp:26
@ CRITICAL
Definition WsfThread.hpp:31
@ ASSIGNED
Definition WsfThread.hpp:29
@ STOPPED
Definition WsfThread.hpp:27
@ PAUSED
Definition WsfThread.hpp:30
@ AVAILABLE
Definition WsfThread.hpp:28
bool BeginCriticalWork()
Definition WsfThread.cpp:121
bool SetFunction(FunctionType aOldFunction, FunctionType aNewFunction)
Definition WsfThread.cpp:134
bool ReadyForWork() const
Definition WsfThread.hpp:44
Copyrights Multiple, All Rights Reserved