summaryrefslogtreecommitdiff
path: root/src/mt/lock.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mt/lock.h')
-rw-r--r--src/mt/lock.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/mt/lock.h b/src/mt/lock.h
new file mode 100644
index 0000000..e019158
--- /dev/null
+++ b/src/mt/lock.h
@@ -0,0 +1,72 @@
1/*************************************************************************
2 *
3 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifndef LOCKH
21#define LOCKH
22
23#include <mt/mstring.h>
24
25// OFFERS TWO LOCKING MECHANISMS
26
27void LockFile(const mstring& path,int prot=0660) throw(merror_t);
28void UnlockFile(const mstring& path);
29
30// These functions create an exclusive lock on path by
31// creating a file path.lock.
32// Works well and is the same mechnism used by
33// mailing systems.
34
35////////////////////////////////////////////
36
37struct proclock_t {
38 pid_t pid;
39 mstring path;
40 proclock_t(const mstring& p,int prot=0660);
41 ~proclock_t();
42};
43
44#define PROCLOCK(p) proclock_t proclock(p)
45
46// The proclock class creates a file named path.lock
47// and stores the curent process id in it.
48// once the destructor is called in the same
49// process, the file is removed.
50
51////////////////////////////////////////////
52
53struct nodelock_t {
54 pid_t pid;
55 mstring path;
56 nodelock_t(const mstring& p,int prot=0660);
57 ~nodelock_t();
58};
59
60#define NODELOCK(p) nodelock_t nodelock(p)
61
62// The nodelock class creates a file named path.lock
63// and stores the curent network node name in it.
64// once the destructor is called in the same
65// process, the file is removed.
66
67////////////////////////////////////////////
68
69void ProcTerminate(const mstring& path,int stime=2);
70
71#endif
72