#pragma once

#include "robbase.h"

//同步对象

#define MAX_PERMIT_COUNT    75

class ROBBASE_API CPermit
{
public:
	CPermit(void);
	~CPermit(void);
	
	BOOL  Create(int count);
	void  Destroy();

	BOOL  Issue();   //主动线程调用签发,当没有许可的时候签发
	BOOL  Apply();   //被动线程申请，当有许可的时候申请。重复申请无效
	                 //如果申请成功，数量会减少1个
	//void  Receipt(); //这个好像没有用

	BOOL  IsEmpty();
	BOOL  IsUseup();
	int   GetCount();
	 
	//撤销所有许可
	//void  Withdraw();
public:
	 TCHAR  m_strName[ROB_MAX_SYNCOBJ_NAME_LEN];

private:
	int     m_nMaxCount;
	int     m_nCurCount;
	DWORD*  m_pArrSema;

	CRITICAL_SECTION m_cs;
};

