Nebula
Loading...
Searching...
No Matches
osxcriticalsection.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13#include "core/types.h"
14
15//------------------------------------------------------------------------------
16namespace OSX
17{
19{
20public:
26 void Enter() const;
28 void Leave() const;
29private:
30 mutable pthread_mutex_t mutex;
31};
32
33//------------------------------------------------------------------------------
36inline
38{
39 pthread_mutexattr_t mutexAttrs;
40 pthread_mutexattr_init(&mutexAttrs);
41 pthread_mutexattr_settype(&mutexAttrs, PTHREAD_MUTEX_RECURSIVE); // allow nesting
42 int res = pthread_mutex_init(&this->mutex, &mutexAttrs);
43 n_assert(0 == res);
44 pthread_mutexattr_destroy(&mutexAttrs);
45}
46
47//------------------------------------------------------------------------------
50inline
52{
53 int res = pthread_mutex_destroy(&this->mutex);
54 n_assert(0 == res);
55}
56
57//------------------------------------------------------------------------------
60inline void
62{
63 pthread_mutex_lock(&this->mutex);
64}
65
66//------------------------------------------------------------------------------
69inline void
71{
72 pthread_mutex_unlock(&this->mutex);
73}
74
75} // namespace OSX
On OSX, pthread mutexes are used for critical sections.
Definition osxcriticalsection.h:19
pthread_mutex_t mutex
Definition osxcriticalsection.h:30
void Leave() const
leave the critical section
Definition osxcriticalsection.h:70
~OSXCriticalSection()
destructor
Definition osxcriticalsection.h:51
void Enter() const
enter the critical section
Definition osxcriticalsection.h:61
OSXCriticalSection()
constructor
Definition osxcriticalsection.h:37
#define n_assert(exp)
Definition debug.h:50
Definition osxsysfunc.h:21