From 5df79c53745fde5d6c3340a2979b1429cd5892c1 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sat, 8 Oct 2011 20:30:28 +0200 Subject: Initial import of htcd system 1.0 Signed-off-by: Henrik Rydberg --- src/mt/mlock.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/mt/mlock.h (limited to 'src/mt/mlock.h') 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 @@ +/************************************************************************* + * + * 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 +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 -- cgit v1.2.3