wrsync.h

来自「The main idea of this work is to create 」· C头文件 代码 · 共 28 行

H
28
字号
#if !defined(AFX_WRSYNC_H__05C0774C_D377_40E2_976A_2C8DF4676B46__INCLUDED_)
#define AFX_WRSYNC_H__05C0774C_D377_40E2_976A_2C8DF4676B46__INCLUDED_

#include "common.h"
/************************************************************************/
/* wrSync class used for threads synchronization.                       */
/************************************************************************/
class wrSync 
{
public:
	wrSync();
	~wrSync();

	VOID WaitToRead();        // Call this to gain shared read access
	VOID WaitToWrite();       // Call this to gain exclusive write access
	VOID Done();              // Call this when done accessing the resource

private:
	KSPIN_LOCK	m_SpinLock;    // Permits exclusive access to other members
	KSEMAPHORE	m_hsemReaders; // Readers wait on this if a writer has access
	KSEMAPHORE	m_hsemWriters; // Writers wait on this if a reader has access
	int    m_nWaitingReaders;	// Number of readers waiting for access
	int    m_nWaitingWriters;	// Number of writers waiting for access
	int    m_nActive;			// Number of threads currently with access
								//   (0=no threads, >0=# of readers, -1=1 writer)
};

#endif // !defined(AFX_WRSYNC_H__05C0774C_D377_40E2_976A_2C8DF4676B46__INCLUDED_)

⌨️ 快捷键说明

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