/************************************************************************* * * 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