59 c_os_mutex = (CRITICAL_SECTION *)malloc(
sizeof(CRITICAL_SECTION));
60 InitializeCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
61 #elif defined(__UNIX__)
62 pthread_mutexattr_t attr;
63 pthread_mutexattr_init(&attr);
66 ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
68 ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
71 printf(
"failed to initialize mutex attributes!\n"); fflush(
NULL_POINTER);
73 c_os_mutex = (pthread_mutex_t *)malloc(
sizeof(pthread_mutex_t));
74 pthread_mutex_init((pthread_mutex_t *)c_os_mutex, &attr);
75 pthread_mutexattr_destroy(&attr);
77 #pragma error("no implementation of mutexes for this OS yet!")
88 if (!c_os_mutex)
return;
90 DeleteCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
92 #elif defined(__UNIX__)
93 pthread_mutex_destroy((pthread_mutex_t *)c_os_mutex);
96 #pragma error("no implementation of mutexes for this OS yet!")
103 if (!c_os_mutex)
return;
105 EnterCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
106 #elif defined(__UNIX__)
107 pthread_mutex_lock((pthread_mutex_t *)c_os_mutex);
109 #pragma error("no implementation of mutexes for this OS yet!")
115 if (!c_os_mutex)
return;
117 LeaveCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
118 #elif defined(__UNIX__)
119 pthread_mutex_unlock((pthread_mutex_t *)c_os_mutex);
121 #pragma error("no implementation of mutexes for this OS yet!")
virtual ~mutex()
Destroys the mutex. It should not be locked upon destruction.
void construct()
Constructor for use with malloc/free instead of new/delete.
void destruct()
Destructor for use with malloc/free instead of new/delete.
void lock()
Clamps down on the mutex, if possible.
virtual void establish_lock()
Satisfies base class requirements for locking.
void unlock()
Gives up the possession of the mutex.
virtual void repeal_lock()
Satisfies base class requirements for unlocking.
mutex()
Constructs a new mutex.
#define NULL_POINTER
The value representing a pointer to nothing.
The guards collection helps in testing preconditions and reporting errors.