From 10077a4216345a4578a18a3840f6ec93d814cf63 Mon Sep 17 00:00:00 2001 From: Mark Calderbank Date: Fri, 23 Jun 2006 23:55:10 +0000 Subject: [PATCH] MVP/Windows convergence --- mutex.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ mutex.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 mutex.cc create mode 100644 mutex.h diff --git a/mutex.cc b/mutex.cc new file mode 100644 index 0000000..1017180 --- /dev/null +++ b/mutex.cc @@ -0,0 +1,51 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP 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. + + VOMP 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 VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "mutex.h" + +Mutex::Mutex() { +#ifndef WIN32 + pthread_mutex_init(&my_mutex, NULL); +#else + my_mutex=CreateMutex(NULL,FALSE,NULL); +#endif +} + +Mutex::~Mutex() { +#ifdef WIN32 + CloseHandle(my_mutex); +#endif +} + +void Mutex::Lock() { +#ifndef WIN32 + pthread_mutex_lock(&my_mutex); +#else + WaitForSingleObject(my_mutex, INFINITE ); +#endif +} + +void Mutex::Unlock() { +#ifndef WIN32 + pthread_mutex_unlock(&my_mutex); +#else + ReleaseMutex(my_mutex); +#endif +} + diff --git a/mutex.h b/mutex.h new file mode 100644 index 0000000..d989da8 --- /dev/null +++ b/mutex.h @@ -0,0 +1,47 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP 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. + + VOMP 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 VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef MUTEX_H +#define MUTEX_H + +#ifndef WIN32 +#include +#else +#include +#include +#endif + + + +class Mutex +{ +public: + Mutex(); + ~Mutex(); + void Lock(); + void Unlock(); +protected: +#ifndef WIN32 + pthread_mutex_t my_mutex; +#else + HANDLE my_mutex; +#endif +}; +#endif -- 2.39.5