summaryrefslogtreecommitdiff
path: root/lib/common/NamedLock.h
blob: a7d0d77829e25e79c60db9ff79510e7eac7a58c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// --------------------------------------------------------------------------
//
// File
//		Name:    NamedLock.h
//		Purpose: A global named lock, implemented as a lock file in file system
//		Created: 2003/08/28
//
// --------------------------------------------------------------------------

#ifndef NAMEDLOCK__H
#define NAMEDLOCK__H

// --------------------------------------------------------------------------
//
// Class
//		Name:    NamedLock
//		Purpose: A global named lock, implemented as a lock file in file system
//		Created: 2003/08/28
//
// --------------------------------------------------------------------------
class NamedLock
{
public:
	NamedLock();
	~NamedLock();
private:
	// No copying allowed
	NamedLock(const NamedLock &);

public:
	bool TryAndGetLock(const std::string& rFilename, int mode = 0755);
# ifdef WIN32
	bool GotLock() {return mFileDescriptor != INVALID_HANDLE_VALUE;}
# else
	bool GotLock() {return mFileDescriptor != -1;}
# endif
	void ReleaseLock();
	
private:
# ifdef WIN32
	HANDLE mFileDescriptor;
# else
	int mFileDescriptor;
# endif

	std::string mFileName;
};

#endif // NAMEDLOCK__H