Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cJobFiber.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cJobFiber_H
7 #define _INC_cJobFiber_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "cJobThreadSet.h"
13 #include "cThreadFiber.h"
15 
16 namespace GrayLib
17 {
19 
21 
23  : public cThreadFiber
24  {
30 
31  typedef cThreadFiber SUPER_t;
32 
33  private:
34  cJobPtr m_pJob;
35  cJobFiberMgr* m_pParentSet;
36 
37  protected:
38  void RemoveCurrentJob();
39  virtual bool ThreadTick() override;
40  virtual void onThreadExit(THREAD_EXITCODE_t nExitCode) override;
41 
42  public:
43  cJobFiber() noexcept;
44  virtual ~cJobFiber();
45 
46  STDMETHOD_(cString, get_Name)() const override
47  {
48  if (m_pJob != nullptr)
49  {
50  return m_pJob->get_Name();
51  }
52  return "JobFiber"; // no current m_pJob running. idle.
53  }
54  cJobPtr get_Job() const
55  {
56  return m_pJob;
57  }
58 
59  HRESULT SleepJob(TIMESYSD_t mSec);
60 
61  void AssignJob(cJobBase* pJob, cJobFiberMgr* pParentSet)
62  {
63  // This thread/fiber is now running a job.
64  ASSERT(pJob != nullptr);
65  ASSERT(pParentSet != nullptr);
66  ASSERT(m_pJob == nullptr); // was idle.
67  m_pJob = pJob; // nullptr = not in use.
68  m_pParentSet = pParentSet;
69  }
70 
72  };
74 
75  //****************************************************************
76 
77  class GRAYLIB_LINK cJobFiberMgr : public cJobThreadSet<cJobFiber>
78  {
83 
84  friend class cJobFiber;
85  public:
86  cJobFiberMgr(int iMaxFibers = 32);
87  ~cJobFiberMgr();
88 
89  HRESULT ScheduleJob(cJobBase* pJob, TIMESYSD_t mSecDelay);
90  void OnTickJobs(TIMESYSD_t mSec);
91  };
92 };
93 
94 #endif
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cJobBase.h:23
Definition: cJobFiber.h:78
Definition: cJobFiber.h:24
cJobPtr get_Job() const
Definition: cJobFiber.h:54
STDMETHOD_(cString, get_Name)() const override
Definition: cJobFiber.h:46
void AssignJob(cJobBase *pJob, cJobFiberMgr *pParentSet)
Definition: cJobFiber.h:61
UNITTEST2_PREDEF(cJobFiber)
Definition: cJobThreadSet.h:76
Definition: cThreadFiber.h:21
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
cRefPtr< cJobFiber > cJobFiberPtr
Definition: cJobFiber.h:73
class __DECL_IMPORT cJobFiberMgr
Definition: cJobFiber.h:20
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28