SUMO - Simulation of Urban MObility
|
00001 /******************************************************************************** 00002 * * 00003 * Mutal exclusion object (required for threads) * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************/ 00022 #ifndef MFXMUTEX_H 00023 #define MFXMUTEX_H 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <fx.h> 00036 #include <utils/common/AbstractMutex.h> 00037 00038 #ifndef WIN32 00039 typedef void* FXThreadMutex; // handle to a mutex 00040 #else 00041 #include <windows.h> 00042 typedef HANDLE FXThreadMutex; // handle to a mutex 00043 #endif 00044 00045 00046 00047 00052 class MFXMutex : public AbstractMutex { 00053 public: 00055 MFXMutex(); 00056 00058 void lock(); 00059 00061 void unlock(); 00062 00064 virtual ~MFXMutex(); 00065 00066 inline FXbool locked() { 00067 return lock_ ? TRUE : FALSE; 00068 } 00069 00070 protected: 00071 FXuint lock_; // lock count 00072 00073 private: 00074 FXThreadMutex mutexHandle; 00075 00076 private: 00077 // dummy copy constructor and operator= to prevent copying 00078 MFXMutex(const MFXMutex&); 00079 MFXMutex& operator=(const MFXMutex&); 00080 00081 }; 00082 00083 #endif // FXMUTEX_H