39 lines
731 B
C++
39 lines
731 B
C++
#include <string>
|
|
#include <windows.h>
|
|
|
|
class SharedMemory
|
|
{
|
|
public:
|
|
/// Open a shared memory
|
|
SharedMemory(const std::string& name);
|
|
/// Create a shared memory
|
|
SharedMemory(const std::string& name,int size);
|
|
/// auto close, destroy memory.
|
|
~SharedMemory();
|
|
|
|
bool isReady() const;
|
|
void* get();
|
|
|
|
private:
|
|
HANDLE hMap;
|
|
void* pMem;
|
|
};
|
|
|
|
class NamedMutex
|
|
{
|
|
public:
|
|
NamedMutex(const std::string& name,bool create=false);
|
|
~NamedMutex();
|
|
|
|
bool isReady() const;
|
|
DWORD getError() const;
|
|
|
|
/// If the mutex has been occupied by this process, wait() will return immediately.
|
|
int wait();
|
|
int wait_for(int ms);
|
|
void release();
|
|
private:
|
|
HANDLE hmtx;
|
|
DWORD errcode;
|
|
};
|