Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cThreadMgr.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_cThreadMgr_H
6 #define _INC_cThreadMgr_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "cThread.h"
13 
14 namespace GrayLib
15 {
16  MIDL_INTERFACE("0C3E2E71-B93C-11d2-AAD0-006007654038") IThreadCloseHandler
17  {
21  virtual void OnThreadClose(THREADID_t nThreadID) = 0;
22  };
23 
25  : public cSingleton<cThreadMgr>
26  {
32 
33  friend class cSingleton<cThreadMgr>;
34  friend class cThread;
36 
37  protected:
41 
42  private:
43  bool AddThread(cThread* pThread);
44  bool RemoveThreadId(THREADID_t nThreadId);
45  bool RemoveThread(cThread* pThread);
46  void ClearTerminatedThreadId(THREADID_t nThreadId);
47 
48  protected:
49  cThreadMgr();
50  ~cThreadMgr();
51 
52  public:
54  {
57  return m_LockThreads;
58  }
59 
60  cThreadPtr GetThreadForId(THREADID_t nThreadID) const noexcept;
61  bool IsValidThreadId(THREADID_t nThreadID) noexcept // static
62  {
65  if (nThreadID == cThreadId::k_NULL)
66  return false;
67  cThreadPtr pThread = GetThreadForId(nThreadID);
68  if (pThread == nullptr)
69  {
70  // Not one of my threads!
71  return false;
72  }
73  return true; // is this a real valid existing thread id ?
74  }
75 
76  cThread* GetCurrentThread() const noexcept;
77  HRESULT CheckAllThreads();
78 
79  void Register(IThreadCloseHandler* pLocal);
80  void UnRegister(IThreadCloseHandler* pLocal);
81  };
82 };
83 
84 #endif // _INC_cThreadMgr_H
#define IGNORE_WARN_INTERFACE(c)
Definition: GrayCore.h:79
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define CHEAPOBJECT_IMPL
Definition: cHeapObject.h:32
Definition: cThreadMgr.h:26
cThreadLockFast & ref_LockThreads() noexcept
Definition: cThreadMgr.h:53
cArrayPtr< IThreadCloseHandler > m_aThreadCloseHandlers
array of callbacks to notify when a thread closes. e.g. cleanup thread local stuff ?
Definition: cThreadMgr.h:40
cThreadLockFast m_LockThreads
lock the whole threading system. to start/stop threads.
Definition: cThreadMgr.h:38
cArraySortHash< cThread, THREADID_t > m_aThreads
just store array of pointers for each cThread. acts the same as a thread local type.
Definition: cThreadMgr.h:39
bool IsValidThreadId(THREADID_t nThreadID) noexcept
Definition: cThreadMgr.h:61
Definition: cThread.h:68
Definition: cArray.h:864
Definition: cArraySortRef.h:60
Definition: cRefPtr.h:225
Definition: cSingleton.h:127
static const THREADID_t k_NULL
Not a valid thread Id.
Definition: cThreadLock.h:64
Definition: cThreadLock.h:205
Definition: cThreadMgr.h:16
Definition: cMesh.h:22
MIDL_INTERFACE("0C3E2E71-B93C-11d2-AAD0-006007654304") IScriptableObj