[c++]代码库
#ifndef SYNOBJ_H
#define SYNOBJ_H
#include <windows.h>
#define CLASS_UNCOPYABLE(classname) \
private: \
classname(const classname&); \
classname& operator=(const classname&);
class Mutex {
CLASS_UNCOPYABLE(Mutex)
public:
Mutex() :_cs() { InitializeCriticalSection(&_cs); }
~Mutex() { DeleteCriticalSection(&_cs); }
void lock() { EnterCriticalSection(&_cs); }
void unlock() { LeaveCriticalSection(&_cs); }
private:
CRITICAL_SECTION _cs;
};
class Lock {
CLASS_UNCOPYABLE(Lock)
public:
explicit Lock(Mutex& cs) :_cs(cs) { _cs.lock(); }
~Lock() { _cs.unlock(); }
private:
Mutex& _cs;
};
#endif/*SYNOBJ_H*/
初级程序员
by: 云代码会员 发表于:2015-06-19 15:36:15 顶(0) | 踩(0) 回复
不错
回复评论