⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mutexwin.h

📁 Many applications use connection/object pool. A program may require a IMAP connection pool and LDAP
💻 H
字号:
#ifndef MUTEX_H
#define MUTEX_H
///////////////////////////////////////////////////////////////////////////////
// Mutex.h
// Rohit Joshi
// It implements the mutex for windows
//////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <process.h>

// Lock class
template <class T > class Lock 
{
	T& obj_; // type object
public:
    // Lock
	Lock(T& obj):obj_(obj)
	{
		obj_.Lock();
	}
	// Unlock
	~Lock()
	{
		obj_.Unlock();
	}
};
// Mutex class for windows
class Mutex
{
public:
	// constructor
    Mutex()
	{
		InitializeCriticalSection(&m_mMutex);
	}
    // destructor
	virtual ~Mutex()
	{
		DeleteCriticalSection(&m_mMutex);
	}
	// lock
	bool Lock()
	{
		EnterCriticalSection(&m_mMutex);
		return true;
	}
	// unlock
	bool Unlock()
	{
		LeaveCriticalSection(&m_mMutex);
		return true;
	}
	// try lock
	bool TryLock()
	{
		/*
		if(TryEnterCriticalSection(&m_mMutex)) {
			return true;
		}else {
		    return false;
		}
		*/
		
	}

private:
    CRITICAL_SECTION  m_mMutex;  // critical section as mutex
    void operator=(Mutex &m_mMutex) {} // private = operator
    Mutex( const Mutex &m_mMutex ) {} // private copy constructor
};




#endif // MUTEX_H

⌨️ 快捷键说明

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