Mutex.h

Go to the documentation of this file.
00001 /* ES40 emulator.
00002  * Copyright (C) 2007-2008 by the ES40 Emulator Project
00003  *
00004  * WWW    : http://sourceforge.net/projects/es40
00005  * E-mail : camiel@camicom.com
00006  * 
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00020  * 
00021  * Although this is not required, the author would appreciate being notified of, 
00022  * and receiving any modifications you may make to the source code that might serve
00023  * the general public.
00024  */
00025 
00037 //
00038 // Mutex.h
00039 //
00040 // $Id: Mutex.h,v 1.1 2008/03/31 19:13:31 iamcamiel Exp $
00041 //
00042 // Library: Foundation
00043 // Package: Threading
00044 // Module:  Mutex
00045 //
00046 // Definition of the Mutex and FastMutex classes.
00047 //
00048 // Copyright (c) 2004-2008, Applied Informatics Software Engineering GmbH.
00049 // and Contributors.
00050 //
00051 // Permission is hereby granted, free of charge, to any person or organization
00052 // obtaining a copy of the software and accompanying documentation covered by
00053 // this license (the "Software") to use, reproduce, display, distribute,
00054 // execute, and transmit the Software, and to prepare derivative works of the
00055 // Software, and to permit third-parties to whom the Software is furnished to
00056 // do so, all subject to the following:
00057 // 
00058 // The copyright notices in the Software and this entire statement, including
00059 // the above license grant, this restriction and the following disclaimer,
00060 // must be included in all copies of the Software, in whole or in part, and
00061 // all derivative works of the Software, unless such copies or derivative
00062 // works are solely in the form of machine-executable object code generated by
00063 // a source language processor.
00064 // 
00065 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00066 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00067 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00068 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00069 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00070 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00071 // DEALINGS IN THE SOFTWARE.
00072 //
00073 
00074 
00075 #ifndef Foundation_Mutex_INCLUDED
00076 #define Foundation_Mutex_INCLUDED
00077 
00078 
00079 #include "VMS/Foundation.h"
00080 #include "VMS/Exception.h"
00081 #include "VMS/ScopedLock.h"
00082 
00083 #include "VMS/Mutex_POSIX.h"
00084 
00085 namespace Poco {
00086 
00087 
00088 class Foundation_API Mutex: private MutexImpl
00097 {
00098 public:
00099         typedef Poco::ScopedLock<Mutex> ScopedLock;
00100         
00101         Mutex();
00103                 
00104         ~Mutex();
00106 
00107         void lock();
00110                 
00111         void lock(long milliseconds);
00119 
00120         bool tryLock();
00124 
00125         bool tryLock(long milliseconds);
00133 
00134         void unlock();
00137         
00138 private:
00139         Mutex(const Mutex&);
00140         Mutex& operator = (const Mutex&);
00141 };
00142 
00143 
00144 class Foundation_API FastMutex: private FastMutexImpl
00152 {
00153 public:
00154         typedef Poco::ScopedLock<FastMutex> ScopedLock;
00155 
00156         FastMutex();
00158                 
00159         ~FastMutex();
00161 
00162         void lock();
00165 
00166         void lock(long milliseconds);
00174 
00175         bool tryLock();
00179 
00180         bool tryLock(long milliseconds);
00188 
00189         void unlock();
00192         
00193 private:
00194         FastMutex(const FastMutex&);
00195         FastMutex& operator = (const FastMutex&);
00196 };
00197 
00198 
00199 //
00200 // inlines
00201 //
00202 inline void Mutex::lock()
00203 {
00204         lockImpl();
00205 }
00206 
00207 
00208 inline void Mutex::lock(long milliseconds)
00209 {
00210         if (!tryLockImpl(milliseconds))
00211                 throw TimeoutException();
00212 }
00213 
00214 
00215 inline bool Mutex::tryLock()
00216 {
00217         return tryLockImpl();
00218 }
00219 
00220 
00221 inline bool Mutex::tryLock(long milliseconds)
00222 {
00223         return tryLockImpl(milliseconds);
00224 }
00225 
00226 
00227 inline void Mutex::unlock()
00228 {
00229         unlockImpl();
00230 }
00231 
00232 
00233 inline void FastMutex::lock()
00234 {
00235         lockImpl();
00236 }
00237 
00238 
00239 inline void FastMutex::lock(long milliseconds)
00240 {
00241         if (!tryLockImpl(milliseconds))
00242                 throw TimeoutException();
00243 }
00244 
00245 
00246 inline bool FastMutex::tryLock()
00247 {
00248         return tryLockImpl();
00249 }
00250 
00251 
00252 inline bool FastMutex::tryLock(long milliseconds)
00253 {
00254         return tryLockImpl(milliseconds);
00255 }
00256 
00257 
00258 inline void FastMutex::unlock()
00259 {
00260         unlockImpl();
00261 }
00262 
00263 
00264 } // namespace Poco
00265 
00266 
00267 #endif // Foundation_Mutex_INCLUDED

SourceForge.net Logo
Project space on SourceForge.net