Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "SimpleMutex.h"
00009 #include "RakAssert.h"
00010
00011 SimpleMutex::SimpleMutex()
00012 {
00013
00014 Init();
00015 }
00016
00017 SimpleMutex::~SimpleMutex()
00018 {
00019
00020
00021 #ifdef _WIN32
00022
00023 DeleteCriticalSection(&criticalSection);
00024 #else
00025 pthread_mutex_destroy(&hMutex);
00026 #endif
00027 }
00028
00029 #ifdef _WIN32
00030 #ifdef _DEBUG
00031 #include <stdio.h>
00032 #endif
00033 #endif
00034
00035 void SimpleMutex::Lock(void)
00036 {
00037
00038
00039
00040 #ifdef _WIN32
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 EnterCriticalSection(&criticalSection);
00071
00072 #else
00073 int error = pthread_mutex_lock(&hMutex);
00074 (void) error;
00075 RakAssert(error==0);
00076 #endif
00077 }
00078
00079 void SimpleMutex::Unlock(void)
00080 {
00081
00082
00083 #ifdef _WIN32
00084
00085 LeaveCriticalSection(&criticalSection);
00086 #else
00087 int error = pthread_mutex_unlock(&hMutex);
00088 (void) error;
00089 RakAssert(error==0);
00090 #endif
00091 }
00092
00093 void SimpleMutex::Init(void)
00094 {
00095 #ifdef _WIN32
00096
00097
00098 InitializeCriticalSection(&criticalSection);
00099 #else
00100 int error = pthread_mutex_init(&hMutex, 0);
00101 (void) error;
00102 RakAssert(error==0);
00103 #endif
00104
00105 }