PCMMutex_impl.h
Go to the documentation of this file.00001 00002 // 00003 // This source file is a part of ParCompMark 00004 // Parallel Compositing Benchmark Framework 00005 // 00006 // for latest info see http://parcompmark.sourceforge.net 00007 00008 // 00009 // Copyright (C) 2006 IT2 ParCompMark Dev. Team 00010 // 00011 // This program is free software; you can redistribute it and/or 00012 // modify it under the terms of the GNU General Public License 00013 // as published by the Free Software Foundation; either version 2 00014 // of the License, or (at your option) any later version. 00015 // 00016 // This program is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU General Public License 00022 // along with this program; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00024 00027 00028 // 00029 // Constructors & destructor 00030 // 00031 00032 inline Mutex::Mutex() 00033 // You have to initialize the following attributes: 00034 // - mMutex 00035 { 00036 pthread_mutexattr_t attr; 00037 00038 pthread_mutexattr_init(&attr); 00039 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_FAST_NP); 00040 pthread_mutex_init(&mMutex, &attr); 00041 pthread_mutexattr_destroy(&attr); 00042 } 00043 00044 /*----------------------------------------------------------------------*/ 00045 00046 inline Mutex::~Mutex() 00047 { 00048 // pthread_mutex_destroy destroys a mutex object, freeing the resources it 00049 // might hold. The mutex must be unlocked on entrance. In the LinuxThreads 00050 // implementation, no resources are associated with mutex objects, thus 00051 // pthread_mutex_destroy actually does nothing except checking that the 00052 // mutex is unlocked. 00053 pthread_mutex_destroy(&mMutex); 00054 } 00055 00056 /*----------------------------------------------------------------------*/ 00057 00058 // 00059 // Methods 00060 // 00061 00062 inline void Mutex::lock() 00063 { 00064 // If successful, the pthread_mutex_lock() function return zero 00065 //Assert(!pthread_mutex_lock(&mMutex) && (mLocked = true), INTERNAL_ERROR, "Mutex::lock"); 00066 pthread_mutex_lock(&mMutex); 00067 mLocked = true; 00068 } 00069 00070 /*----------------------------------------------------------------------*/ 00071 00072 inline bool Mutex::trylock() 00073 { 00074 // pthread_mutex_trylock() returns zero if locking succeed 00075 return pthread_mutex_trylock(&mMutex) && (mLocked = true); 00076 } 00077 00078 /*----------------------------------------------------------------------*/ 00079 00080 inline void Mutex::unlock() 00081 { 00082 // If successful, the pthread_mutex_lock() function return zero 00083 //Assert(!pthread_mutex_unlock(&mMutex) && !(mLocked = false), INTERNAL_ERROR, "Mutex::unlock"); 00084 pthread_mutex_unlock(&mMutex); 00085 mLocked = false; 00086 }