lock.h

来自「该模块基于USB FX2开发板」· C头文件 代码 · 共 74 行

H
74
字号
/********************************************************************
//	Project:			Evolution
//
//	FileName:           Lock.h
//
//	Author:				
//
//	Created:			
//
//	Function:			Lock & Mutex
//
//	Remark:				
//
*********************************************************************/
#ifndef	_LOCK_H_
#define	_LOCK_H_

#ifdef WIN32
#include <windows.h>
#else
#include <pthread.h>
#endif

class CMutex
{
    friend class CLock;
public:
#ifdef WIN32
	CMutex ()
	{ 
		InitializeCriticalSection (&_critSection);
	}
    ~CMutex ()
	{ 
		DeleteCriticalSection (&_critSection); 
	}
	void Acquire () 
	{ 
		EnterCriticalSection (&_critSection);
	}
	void Release () 
	{ 
		LeaveCriticalSection (&_critSection);
	}
#else
	CMutex ()
	{
		pthread_mutex_init(&_critSection, NULL);
	}

	~CMutex ()
	{
		pthread_mutex_destroy(&_critSection);
	}
	void Acquire () 
	{ 
		pthread_mutex_lock(&_critSection);
	}
	void Release () 
	{ 
		pthread_mutex_unlock(&_critSection);
	}
#endif

private:
#ifdef WIN32
	CRITICAL_SECTION _critSection;
#else
	pthread_mutex_t _critSection;
#endif
};

#endif	//_LOCK_H_

⌨️ 快捷键说明

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