summaryrefslogtreecommitdiff
path: root/src/mt/mlock.h
blob: 4639cf4520e53387ef014d7533e52187b535a199 (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
/*************************************************************************
 *
 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#ifndef MLOCKH
#define MLOCKH

#if 1
#include <pthread.h>
typedef pthread_mutex_t mutex_t;
typedef pthread_cond_t mtcond_t;
const mutex_t MUTEX_INIT=PTHREAD_MUTEX_INITIALIZER;
const mtcond_t MTCOND_INIT=PTHREAD_COND_INITIALIZER;
struct mlock_t {
  mutex_t* lock;

  mlock_t(mutex_t& m) { pthread_mutex_lock(lock=&m); }
  ~mlock_t() { if(lock) pthread_mutex_unlock(lock); }
};
#define MLOCK(m) mlock_t mlock(m)
#define MSUSPEND(m,c) { MLOCK(m); pthread_cond_wait(&c,&m); }
#define MCONTINUE(c) pthread_cond_signal(&c)
#else
typedef int mutex_t;
typedef int mtcond_t;
const mutex_t MUTEX_INIT=0;
const mtcond_t MTCOND_INIT=0;
#define MLOCK(m)
#define MSUSPEND(m,c)
#define MCONTINUE(c)
#endif

#endif