Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
vhacdMutex.h
Go to the documentation of this file.
1
49#pragma once
50
51#if defined(WIN32)
52
53#ifndef _WIN32_WINNT
54#define _WIN32_WINNT 0x400
55#endif
56#include <windows.h>
57#pragma comment(lib, "winmm.lib")
58#endif
59
60#if defined(__linux__)
61#include <ctime>
62#define __stdcall
63#endif
64
65#if defined(__APPLE__) || defined(__linux__)
66#include <pthread.h>
67#include <cassert>
68#endif
69
70#if defined(__APPLE__)
71#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE
72#endif
73
74#define VHACD_DEBUG
75
76//#define VHACD_NDEBUG
77#ifdef VHACD_NDEBUG
78#define VHACD_VERIFY(x) (x)
79#else
80#define VHACD_VERIFY(x) assert((x))
81#endif
82
83namespace tesseract_collision
84{
85namespace VHACD
86{
87class Mutex
88{
89public:
90 Mutex(void)
91 {
92#if defined(WIN32) || defined(_XBOX)
93 InitializeCriticalSection(&m_mutex);
94#elif defined(__APPLE__) || defined(__linux__)
95 pthread_mutexattr_t mutexAttr; // Mutex Attribute
96 VHACD_VERIFY(pthread_mutexattr_init(&mutexAttr) == 0);
97 VHACD_VERIFY(pthread_mutexattr_settype(&mutexAttr, PTHREAD_MUTEX_RECURSIVE_NP) == 0);
98 VHACD_VERIFY(pthread_mutex_init(&m_mutex, &mutexAttr) == 0);
99 VHACD_VERIFY(pthread_mutexattr_destroy(&mutexAttr) == 0);
100 (void)(mutexAttr);
101#endif
102 }
103 ~Mutex(void)
104 {
105#if defined(WIN32) || defined(_XBOX)
106 DeleteCriticalSection(&m_mutex);
107#elif defined(__APPLE__) || defined(__linux__)
108 VHACD_VERIFY(pthread_mutex_destroy(&m_mutex) == 0);
109#endif
110 }
111 void Lock(void)
112 {
113#if defined(WIN32) || defined(_XBOX)
114 EnterCriticalSection(&m_mutex);
115#elif defined(__APPLE__) || defined(__linux__)
116 VHACD_VERIFY(pthread_mutex_lock(&m_mutex) == 0);
117#endif
118 }
119 bool TryLock(void)
120 {
121#if defined(WIN32) || defined(_XBOX)
122 bool bRet = false;
123 // assert(("TryEnterCriticalSection seems to not work on XP???", 0));
124 bRet = TryEnterCriticalSection(&m_mutex) ? true : false;
125 return bRet;
126#elif defined(__APPLE__) || defined(__linux__)
127 int32_t result = pthread_mutex_trylock(&m_mutex);
128 return (result == 0);
129#endif
130 }
131
132 void Unlock(void)
133 {
134#if defined(WIN32) || defined(_XBOX)
135 LeaveCriticalSection(&m_mutex);
136#elif defined(__APPLE__) || defined(__linux__)
137 VHACD_VERIFY(pthread_mutex_unlock(&m_mutex) == 0);
138#endif
139 }
140
141private:
142#if defined(WIN32) || defined(_XBOX)
143 CRITICAL_SECTION m_mutex;
144#elif defined(__APPLE__) || defined(__linux__)
145 pthread_mutex_t m_mutex;
146#endif
147};
148} // namespace VHACD
149} // namespace tesseract_collision
Definition: vhacdMutex.h:88
void Unlock(void)
Definition: vhacdMutex.h:132
void Lock(void)
Definition: vhacdMutex.h:111
bool TryLock(void)
Definition: vhacdMutex.h:119
~Mutex(void)
Definition: vhacdMutex.h:103
Mutex(void)
Definition: vhacdMutex.h:90
Definition: bullet_cast_bvh_manager.h:49
#define VHACD_VERIFY(x)
Definition: vhacdMutex.h:80