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

Mutex.hh

Go to the documentation of this file.
00001 /*
00002 
00003     Mutex class, header
00004     Copyright (C) 1999-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 #ifndef USE_NPTL
00024 #include <pthread.h>
00025 #else
00026 #include <nptl/pthread.h>
00027 #endif
00028 
00029 
00030 #ifndef MUTEX_HH
00031     #define MUTEX_HH
00032 
00033 
00037     class clMutex
00038     {
00039             pthread_mutex_t pthmMutex;
00040         public:
00044             clMutex () { pthread_mutex_init(&pthmMutex, NULL); }
00048             ~clMutex () { pthread_mutex_destroy(&pthmMutex); }
00055             bool Wait ()
00056                 { 
00057                     if (pthread_mutex_lock(&pthmMutex) != 0)
00058                         return false;
00059                     return true;
00060                 }
00066             bool Release ()
00067                 { 
00068                     if (pthread_mutex_unlock(&pthmMutex) != 0)
00069                         return false;
00070                     return true;
00071                 }
00077             bool TryLock ()
00078                 {
00079                     if (pthread_mutex_trylock(&pthmMutex) != 0)
00080                         return false;
00081                     return true;
00082                 }
00089             pthread_mutex_t *GetPtr () { return (&pthmMutex); }
00090     };
00091 
00092 #endif

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