11 #ifndef MI_BASE_LOCK_H
12 #define MI_BASE_LOCK_H
19 #ifndef MI_PLATFORM_WINDOWS
23 #include <mi/base/miwindows.h>
125 #ifndef MI_PLATFORM_WINDOWS
127 pthread_mutex_t m_mutex;
130 CRITICAL_SECTION m_critical_section;
219 #ifndef MI_PLATFORM_WINDOWS
221 pthread_mutex_t m_mutex;
224 CRITICAL_SECTION m_critical_section;
228 #ifndef MI_FOR_DOXYGEN_ONLY
232 #ifndef MI_PLATFORM_WINDOWS
233 pthread_mutexattr_t mutex_attributes;
234 pthread_mutexattr_init( &mutex_attributes);
235 pthread_mutexattr_settype( &mutex_attributes, PTHREAD_MUTEX_ERRORCHECK);
236 pthread_mutex_init( &m_mutex, &mutex_attributes);
238 InitializeCriticalSection( &m_critical_section);
245 #ifndef MI_PLATFORM_WINDOWS
246 int result = pthread_mutex_destroy( &m_mutex);
251 DeleteCriticalSection( &m_critical_section);
257 #ifndef MI_PLATFORM_WINDOWS
258 int result = pthread_mutex_lock( &m_mutex);
259 if( result == EDEADLK) {
264 EnterCriticalSection( &m_critical_section);
275 #ifndef MI_PLATFORM_WINDOWS
276 int result = pthread_mutex_trylock( &m_mutex);
279 mi_base_assert( result == 0 || result == EBUSY || result == EDEADLK);
282 BOOL result = TryEnterCriticalSection( &m_critical_section);
286 LeaveCriticalSection( &m_critical_section);
296 #ifndef MI_PLATFORM_WINDOWS
297 int result = pthread_mutex_unlock( &m_mutex);
303 LeaveCriticalSection( &m_critical_section);
337 if( m_lock && m_lock->try_lock())
352 #ifndef MI_PLATFORM_WINDOWS
353 pthread_mutexattr_t mutex_attributes;
354 pthread_mutexattr_init( &mutex_attributes);
355 pthread_mutexattr_settype( &mutex_attributes, PTHREAD_MUTEX_RECURSIVE);
356 pthread_mutex_init( &m_mutex, &mutex_attributes);
358 InitializeCriticalSection( &m_critical_section);
364 #ifndef MI_PLATFORM_WINDOWS
365 int result = pthread_mutex_destroy( &m_mutex);
369 DeleteCriticalSection( &m_critical_section);
375 #ifndef MI_PLATFORM_WINDOWS
376 int result = pthread_mutex_lock( &m_mutex);
380 EnterCriticalSection( &m_critical_section);
386 #ifndef MI_PLATFORM_WINDOWS
387 int result = pthread_mutex_trylock( &m_mutex);
391 BOOL result = TryEnterCriticalSection( &m_critical_section);
398 #ifndef MI_PLATFORM_WINDOWS
399 int result = pthread_mutex_unlock( &m_mutex);
403 LeaveCriticalSection( &m_critical_section);
437 if( m_lock && m_lock->try_lock())
450 #endif // MI_FOR_DOXYGEN_ONLY
458 #endif // MI_BASE_LOCK_H