RWLock_POSIX.h
Go to the documentation of this file.
00001 //
00002 // RWLock_POSIX.h
00003 //
00004 // $Id: //poco/1.3/Foundation/include/Poco/RWLock_POSIX.h#1 $
00005 //
00006 // Library: Foundation
00007 // Package: Threading
00008 // Module:  RWLock
00009 //
00010 // Definition of the RWLockImpl class for POSIX Threads.
00011 //
00012 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
00013 // and Contributors.
00014 //
00015 // Permission is hereby granted, free of charge, to any person or organization
00016 // obtaining a copy of the software and accompanying documentation covered by
00017 // this license (the "Software") to use, reproduce, display, distribute,
00018 // execute, and transmit the Software, and to prepare derivative works of the
00019 // Software, and to permit third-parties to whom the Software is furnished to
00020 // do so, all subject to the following:
00021 // 
00022 // The copyright notices in the Software and this entire statement, including
00023 // the above license grant, this restriction and the following disclaimer,
00024 // must be included in all copies of the Software, in whole or in part, and
00025 // all derivative works of the Software, unless such copies or derivative
00026 // works are solely in the form of machine-executable object code generated by
00027 // a source language processor.
00028 // 
00029 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00030 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00031 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00032 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00033 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00034 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00035 // DEALINGS IN THE SOFTWARE.
00036 //
00037 
00038 
00039 #ifndef Foundation_RWLock_POSIX_INCLUDED
00040 #define Foundation_RWLock_POSIX_INCLUDED
00041 
00042 
00043 #include "Poco/Foundation.h"
00044 #include "Poco/Exception.h"
00045 #include <pthread.h>
00046 #include <errno.h>
00047 
00048 
00049 namespace Poco {
00050 
00051 
00052 class Foundation_API RWLockImpl
00053 {
00054 protected:
00055         RWLockImpl();
00056         ~RWLockImpl();
00057         void readLockImpl();
00058         bool tryReadLockImpl();
00059         void writeLockImpl();
00060         bool tryWriteLockImpl();
00061         void unlockImpl();
00062         
00063 private:
00064         pthread_rwlock_t _rwl;
00065 };
00066 
00067 
00068 //
00069 // inlines
00070 //
00071 inline void RWLockImpl::readLockImpl()
00072 {
00073         if (pthread_rwlock_rdlock(&_rwl)) 
00074                 throw SystemException("cannot lock reader/writer lock");
00075 }
00076 
00077 
00078 inline bool RWLockImpl::tryReadLockImpl()
00079 {
00080         int rc = pthread_rwlock_tryrdlock(&_rwl);
00081         if (rc == 0)
00082                 return true;
00083         else if (rc == EBUSY)
00084                 return false;
00085         else
00086                 throw SystemException("cannot lock reader/writer lock");
00087 
00088 }
00089 
00090 
00091 inline void RWLockImpl::writeLockImpl()
00092 {
00093         if (pthread_rwlock_wrlock(&_rwl)) 
00094                 throw SystemException("cannot lock reader/writer lock");
00095 }
00096 
00097 
00098 inline bool RWLockImpl::tryWriteLockImpl()
00099 {
00100         int rc = pthread_rwlock_trywrlock(&_rwl);
00101         if (rc == 0)
00102                 return true;
00103         else if (rc == EBUSY)
00104                 return false;
00105         else
00106                 throw SystemException("cannot lock reader/writer lock");
00107 
00108 }
00109 
00110 
00111 inline void RWLockImpl::unlockImpl()
00112 {
00113         if (pthread_rwlock_unlock(&_rwl))
00114                 throw SystemException("cannot unlock mutex");
00115 }
00116 
00117 
00118 } // namespace Poco
00119 
00120 
00121 #endif // Foundation_RWLock_POSIX_INCLUDED


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:19