From: Christian P. <cp...@us...> - 2005-04-23 10:54:54
|
Update of /cvsroot/pclasses/pclasses2/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7503/src Added Files: AtomicMutex.posix.cpp AtomicMutex.win32.cpp Log Message: Added AtomicMutex in favor of System::CriticalSection to get rid of dependency on System. --- NEW FILE: AtomicMutex.posix.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program 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 Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/AtomicTraits.h" #include <pthread.h> namespace P { namespace Traits { AtomicTraits::Mutex() : _handle((unsigned long)new pthread_mutex_t) { pthread_mutex_init((pthread_mutex_t*)_handle, 0); } AtomicTraits::~Mutex() { pthread_mutex_destroy((pthread_mutex_t*)_handle); delete (pthread_mutex_t*)_handle; } void AtomicTraits::Mutex::lock() throw() { pthread_mutex_lock((pthread_mutex_t*)_handle); } void AtomicTraits::Mutex::unlock() throw() { pthread_mutex_unlock((pthread_mutex_t*)_handle); } AtomicTraits::Mutex::ScopedLock(Mutex& mtx) : _mtx(mtx) { _mtx.lock(); } AtomicTraits::Mutex::~ScopedLock() { _mtx.unlock(); } } // !namespace Traits } // !namespace P --- NEW FILE: AtomicMutex.win32.cpp --- /*************************************************************************** * Copyright (C) 2005 by Christian Prochnow, SecuLogiX GmbH * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program 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 Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/AtomicTraits.h" #include <windows.h> namespace P { namespace Traits { AtomicTraits::Mutex() : _handle((unsigned long)new CRITICAL_SECTION) { InitializeCriticalSection((CRITICAL_SECTION*)_handle)); } AtomicTraits::~Mutex() { DeleteCriticalSection((CRITICAL_SECTION*)_handle)); delete (CRITICAL_SECTION*)_handle; } void AtomicTraits::Mutex::lock() throw() { EnterCriticalSection((CRITICAL_SECTION*)_handle)); } void AtomicTraits::Mutex::unlock() throw() { LeaveCriticalSection((CRITICAL_SECTION*)_handle)); } AtomicTraits::Mutex::ScopedLock(Mutex& mtx) : _mtx(mtx) { _mtx.lock(); } AtomicTraits::Mutex::~ScopedLock() { _mtx.unlock(); } } // !namespace Traits } // !namespace P |