summaryrefslogtreecommitdiff
path: root/src/mt/mlock.h
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
committerHenrik Rydberg <rydberg@euromail.se>2011-10-08 20:30:28 +0200
commit5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch)
tree1a81af141708b826e9c61e8a04019994fcca8298 /src/mt/mlock.h
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/mt/mlock.h')
-rw-r--r--src/mt/mlock.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/mt/mlock.h b/src/mt/mlock.h
new file mode 100644
index 0000000..4639cf4
--- /dev/null
+++ b/src/mt/mlock.h
@@ -0,0 +1,48 @@
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 MLOCKH
21#define MLOCKH
22
23#if 1
24#include <pthread.h>
25typedef pthread_mutex_t mutex_t;
26typedef pthread_cond_t mtcond_t;
27const mutex_t MUTEX_INIT=PTHREAD_MUTEX_INITIALIZER;
28const mtcond_t MTCOND_INIT=PTHREAD_COND_INITIALIZER;
29struct mlock_t {
30 mutex_t* lock;
31
32 mlock_t(mutex_t& m) { pthread_mutex_lock(lock=&m); }
33 ~mlock_t() { if(lock) pthread_mutex_unlock(lock); }
34};
35#define MLOCK(m) mlock_t mlock(m)
36#define MSUSPEND(m,c) { MLOCK(m); pthread_cond_wait(&c,&m); }
37#define MCONTINUE(c) pthread_cond_signal(&c)
38#else
39typedef int mutex_t;
40typedef int mtcond_t;
41const mutex_t MUTEX_INIT=0;
42const mtcond_t MTCOND_INIT=0;
43#define MLOCK(m)
44#define MSUSPEND(m,c)
45#define MCONTINUE(c)
46#endif
47
48#endif