mysemaphore.h

来自「socket 编程实例 singleServerMultipleClientSr」· C头文件 代码 · 共 54 行

H
54
字号
#ifndef mySemaphore_H
#define mySemaphore_H

#define OPEN 0
#define CREATE 1

#define _WIN32_WINNT 0x0400

#include <windows.h>
#include <winuser.h>
#include <winbase.h>
#include <string>
using namespace std;

class mySemaphore
{

public:

    mySemaphore(string& sName=string(""),
		        long initialCount=0,long maxCount=1,
				int accessMode=CREATE,BOOL canInherit=TRUE);

    virtual ~mySemaphore();

public:

    void closeSemaphore();    
	BOOL lock(BOOL wait=TRUE);
    void unlock();

public:

	string& getSemaphoreName() { return semaphoreName; }
	long    getInitialCount()  { return initCount; }
    long    getMaxCount()      { return maxCount; }
	BOOL    getInerit()        { return inherit; }
	
private:

	void getErrorDetail(int&,string&);

private:

	long initCount;   // initialCount 
	long maxCount;    // max count
    BOOL inherit;     // can be inherited by child

    string semaphoreName;
    HANDLE semaphore;
    LPSECURITY_ATTRIBUTES sa;
};
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?