![]() |
Mutex.cppGo to the documentation of this file.00001 00005 /* 00006 Copyright (C) 2004-2011 Anders Hedstrom 00007 00008 This library is made available under the terms of the GNU GPL, with 00009 the additional exemption that compiling, linking, and/or using OpenSSL 00010 is allowed. 00011 00012 If you would like to use this library in a closed-source application, 00013 a separate license agreement is available. For information about 00014 the closed-source license agreement for the C++ sockets library, 00015 please visit http://www.alhem.net/Sockets/license.html and/or 00016 email license@alhem.net. 00017 00018 This program is free software; you can redistribute it and/or 00019 modify it under the terms of the GNU General Public License 00020 as published by the Free Software Foundation; either version 2 00021 of the License, or (at your option) any later version. 00022 00023 This program is distributed in the hope that it will be useful, 00024 but WITHOUT ANY WARRANTY; without even the implied warranty of 00025 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00026 GNU General Public License for more details. 00027 00028 You should have received a copy of the GNU General Public License 00029 along with this program; if not, write to the Free Software 00030 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00031 */ 00032 #include "Mutex.h" 00033 00034 #ifdef SOCKETS_NAMESPACE 00035 namespace SOCKETS_NAMESPACE { 00036 #endif 00037 00038 00039 Mutex::Mutex() 00040 { 00041 #ifdef _WIN32 00042 m_mutex = ::CreateMutex(NULL, FALSE, NULL); 00043 #else 00044 pthread_mutex_init(&m_mutex, NULL); 00045 #endif 00046 } 00047 00048 00049 Mutex::~Mutex() 00050 { 00051 #ifdef _WIN32 00052 ::CloseHandle(m_mutex); 00053 #else 00054 pthread_mutex_destroy(&m_mutex); 00055 #endif 00056 } 00057 00058 00059 void Mutex::Lock() const 00060 { 00061 #ifdef _WIN32 00062 DWORD d = WaitForSingleObject(m_mutex, INFINITE); 00064 #else 00065 pthread_mutex_lock(&m_mutex); 00066 #endif 00067 } 00068 00069 00070 void Mutex::Unlock() const 00071 { 00072 #ifdef _WIN32 00073 ::ReleaseMutex(m_mutex); 00074 #else 00075 pthread_mutex_unlock(&m_mutex); 00076 #endif 00077 } 00078 00079 00080 #ifdef SOCKETS_NAMESPACE 00081 } 00082 #endif 00083 |