Mutex.cpp (1247B)
1 /* 2 Copyright (C) 2006-2009 Nasca Octavian Paul 3 Author: Nasca Octavian Paul 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of version 2 of the GNU General Public License 7 as published by the Free Software Foundation. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License (version 2) for more details. 13 14 You should have received a copy of the GNU General Public License (version 2) 15 along with this program; if not, write to the Free Software Foundation, 16 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 #include "Mutex.h" 19 Mutex::Mutex(){ 20 #ifdef WINDOWS 21 InitializeCriticalSection(&mutex); 22 #else 23 pthread_mutex_init(&mutex,NULL); 24 #endif 25 }; 26 27 Mutex::~Mutex(){ 28 #ifdef WINDOWS 29 DeleteCriticalSection(&mutex); 30 #else 31 pthread_mutex_destroy(&mutex); 32 #endif 33 }; 34 35 36 void Mutex::lock(){ 37 #ifdef WINDOWS 38 EnterCriticalSection(&mutex); 39 #else 40 pthread_mutex_lock(&mutex); 41 #endif 42 }; 43 44 void Mutex::unlock(){ 45 #ifdef WINDOWS 46 LeaveCriticalSection(&mutex); 47 #else 48 pthread_mutex_unlock(&mutex); 49 #endif 50 }; 51