MRXT: The Multi-Robot eXploration Tool
Multi-Robot autonomous exploration and mapping simulator.
src/mylib/ClMutex.cpp
00001 #include "ClMutex.h"
00002 #include <stdio.h>
00003 
00004 ClMutex::ClMutex(void)
00005 {
00006 #ifdef WIN32
00007    m_mutex = CreateMutex(NULL,FALSE,NULL);
00008 #else
00009    pthread_mutexattr_t mattr;
00010 
00011    pthread_mutexattr_init( &mattr );
00012    pthread_mutex_init(&m_mutex,&mattr);
00013 
00014 #endif
00015 }
00016 
00017 ClMutex::~ClMutex(void)
00018 {
00019 #ifdef WIN32
00020         WaitForSingleObject(m_mutex,INFINITE);
00021         CloseHandle(m_mutex);
00022 #else
00023         pthread_mutex_lock(&m_mutex);
00024         pthread_mutex_unlock(&m_mutex);
00025         pthread_mutex_destroy(&m_mutex);
00026 #endif
00027 }
00028 
00029 void
00030 ClMutex::lock()
00031 {
00032 #ifdef WIN32
00033         WaitForSingleObject(m_mutex,INFINITE);
00034 #else
00035         pthread_mutex_lock(&m_mutex);
00036 #endif
00037 }
00038 
00039 void 
00040 ClMutex::unlock()
00041 {
00042 #ifdef WIN32
00043         ReleaseMutex(m_mutex);
00044 #else
00045         pthread_mutex_unlock(&m_mutex);
00046 #endif
00047 }
00048 
 All Classes Functions Variables Typedefs