Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

mutex.h

00001 /***************************************************************************
00002                   mutex.h  -  Mutex wrapper and automatic lock
00003                              -------------------
00004     begin                : Tue Feb 12 2002
00005     copyright            : (C) 2002 by Reality Rift Studios
00006     email                : mattias@realityrift.com
00007  ***************************************************************************
00008 
00009  The contents of this file are subject to the Mozilla Public License Version
00010  1.1 (the "License"); you may not use this file except in compliance with
00011  the License. You may obtain a copy of the License at 
00012  http://www.mozilla.org/MPL/
00013 
00014  Software distributed under the License is distributed on an "AS IS" basis,
00015  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00016  for the specific language governing rights and limitations under the
00017  License.
00018 
00019  The Original Code is the NeoEngine, mutex.h
00020 
00021  The Initial Developer of the Original Code is Mattias Jansson.
00022  Portions created by Mattias Jansson are Copyright (C) 2002
00023  Reality Rift Studios. All Rights Reserved.
00024 
00025  ***************************************************************************/
00026 
00027 #ifndef __NEMUTEX_H
00028 #define __NEMUTEX_H
00029 
00030 
00031 #include "base.h"
00032 
00033 #ifdef WIN32
00034 #  ifndef WIN32_LEAN_AND_MEAN
00035 #    define WIN32_LEAN_AND_MEAN
00036 #  endif
00037 #  ifndef NOGDI
00038 #    define NOGDI
00039 #  endif
00040 #  include <windows.h>
00041 #elif defined(POSIX) || defined(__APPLE__)
00042 #  include <pthread.h>
00043 #endif
00044 
00045 #include <string>
00046 
00047 
00048 namespace NeoEngine
00049 {
00050 
00051 
00056 class NEOENGINE_API MutexObject
00057 {
00058     private:
00059 
00060 #ifdef WIN32
00061 
00063         HANDLE                                        m_kMutex;
00064 
00066         HANDLE                                        m_kEvent;
00067 
00068 #elif defined(POSIX) || defined(__APPLE__)
00069 
00071         pthread_mutex_t                               m_kMutex;
00072 
00074         pthread_cond_t                                m_kCond;
00075 
00076 #endif
00077 
00079         std::string                                   m_strMutexName;
00080   
00081   
00082     public:
00083   
00088                                                       MutexObject( const std::string &rstrMutexName = "_noname" );
00089 
00093         virtual                                      ~MutexObject();
00094 
00098         void                                          Lock();
00099 
00103         void                                          Unlock();
00104 
00108         void                                          WaitForEvent();
00109 
00113         void                                          BroadcastEvent();
00114 
00119         void                                          SetName( const std::string &rstrName ) { Lock(); m_strMutexName = rstrName; Unlock(); }
00120 };
00121 
00122 
00123 
00124 
00145 class NEOENGINE_API MutexLock
00146 {
00147     private:
00148     
00150         MutexObject                                  *m_pkMutexObject;
00151         
00152 
00153     public:
00154     
00159                                                       MutexLock( MutexObject *pkMutexObject );
00160         
00164         virtual                                      ~MutexLock();
00165 };
00166 
00167 
00168 }; // namespace NeoEngine
00169 
00170 
00171 #endif  // __NEMUTEX_H

Generated on Wed Jan 21 14:21:06 2004 for NeoEngine by doxygen 1.3.5