Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSharedMemory.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cSharedMemory_H
7 #define _INC_cSharedMemory_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
17 
18 
19 namespace GrayLib
20 {
22 
23 #pragma pack(1)
25  {
31 
32  PROCESSID_t m_nMasterId;
34  PROCESSID_t m_nDestId;
35  size_t m_nLength;
36  BYTE m_Data[1];
37 
39  };
40 #pragma pack() // end packing.
41 
42 
43  class GRAYLIB_LINK cSharedContext : public cSingleton<cSharedContext>
44  {
47 
48  public:
49  static const GChar_t* const k_pszMutexName;
50 
51  const PROCESSID_t m_Id;
54 
55  public:
57  virtual ~cSharedContext();
58 
59  bool isLockedByMe() const noexcept
60  {
62  if (m_pMem == nullptr)
63  return false;
64  return (m_pMem->m_LockId.get_Value() == m_Id);
65  }
66  };
67 
69  {
72 
73  public:
76 
77  public:
78  cSharedAccess();
79  ~cSharedAccess();
80 
81  HRESULT ReadWrite(cHeapBlock& reader, const cMemBlock& writer, TIMESYSD_t nWaitTime=0);
82  };
83 
85  {
86  // Only the master uses this class.
87  // stack based. Locks shared memory for my use.
88 
89  public:
90  HRESULT ReadWrite(cHeapBlock& reader, PROCESSID_t nDestId, const cMemBlock& writer, TIMESYSD_t nWaitTime = 0);
91  };
92 }
93 #endif
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cSharedMemory.h:69
cSharedContext & m_c
Definition: cSharedMemory.h:74
bool m_bLockedByMe
Definition: cSharedMemory.h:75
Definition: cSharedMemory.h:44
bool isLockedByMe() const noexcept
Definition: cSharedMemory.h:59
static const GChar_t *const k_pszMutexName
Signal that there is data to be read. (by someone)
Definition: cSharedMemory.h:49
cSharedMemory * m_pMem
The shared memory we all use. Created by master.
Definition: cSharedMemory.h:52
cThreadLockMutex m_Mutex
Wait on this to signal read.
Definition: cSharedMemory.h:53
const PROCESSID_t m_Id
My id.
Definition: cSharedMemory.h:51
Definition: cSharedMemory.h:85
Definition: cHeap.h:156
TYPE get_Value() const noexcept
Definition: cInterlockedVal.h:495
Definition: cMem.h:311
Definition: cSingleton.h:127
Definition: cThreadLock.h:252
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
Definition: cSharedMemory.h:25
PROCESSID_t m_nDestId
Who is the payload for?
Definition: cSharedMemory.h:34
PROCESSID_t m_nMasterId
PROCESSID_BAD = no master present.
Definition: cSharedMemory.h:32
UNITTEST_FRIEND(cSharedMemory)
cInterlockedVal< PROCESSID_t > m_LockId
Locked for write. PROCESSID_BAD = not locked. should be cThreadLockMutex ??
Definition: cSharedMemory.h:33
size_t m_nLength
Length of the data payload.
Definition: cSharedMemory.h:35