Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

RWLock.hh

Go to the documentation of this file.
00001 /*
00002 
00003     Read-write locks class, header
00004     Copyright (C) 2001-2003 Jussi Laako
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 */
00021 
00022 
00023 #ifdef _XOPEN_SOURCE
00024 #   if (_XOPEN_SOURCE < 600)
00025 #       undef _XOPEN_SOURCE
00026 #       define _XOPEN_SOURCE 600
00027 #   endif
00028 #else
00029 #   define _XOPEN_SOURCE 600
00030 #endif
00031 
00032 
00033 #ifndef USE_NPTL
00034 #include <pthread.h>
00035 #else
00036 #include <nptl/pthread.h>
00037 #endif
00038 
00039 
00040 #ifndef RWLOCK_HH
00041 #define RWLOCK_HH
00042 
00043 
00047     class clRWLock
00048     {
00049             pthread_rwlock_t ptrwlLock;
00050         public:
00054             clRWLock ()
00055                 { pthread_rwlock_init(&ptrwlLock, NULL); }
00059             ~clRWLock ()
00060                 { pthread_rwlock_destroy(&ptrwlLock); }
00067             bool WaitRead ()
00068                 {
00069                     if (pthread_rwlock_rdlock(&ptrwlLock) != 0)
00070                         return false;
00071                     return true;
00072                 }
00080             bool WaitWrite ()
00081                 {
00082                     if (pthread_rwlock_wrlock(&ptrwlLock) != 0)
00083                         return false;
00084                     return true;
00085                 }
00091             bool Release ()
00092                 {
00093                     if (pthread_rwlock_unlock(&ptrwlLock) != 0)
00094                         return false;
00095                     return true;
00096                 }
00102             bool TryRead ()
00103                 {
00104                     if (pthread_rwlock_tryrdlock(&ptrwlLock) != 0)
00105                         return false;
00106                     return true;
00107                 }
00113             bool TryWrite ()
00114                 {
00115                     if (pthread_rwlock_trywrlock(&ptrwlLock) != 0)
00116                         return false;
00117                     return true;
00118                 }
00119     };
00120 
00121 #endif

Generated on Tue Mar 2 19:46:45 2004 for libDSP by doxygen 1.3.6