53 c_os_mutex = (CRITICAL_SECTION *)malloc(
sizeof(CRITICAL_SECTION));
54 InitializeCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
55 #elif defined(__UNIX__)
56 pthread_mutexattr_t attr;
57 pthread_mutexattr_init(&attr);
60 ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
62 ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
65 printf(
"failed to initialize mutex attributes!\n"); fflush(
NULL_POINTER);
67 c_os_mutex = (pthread_mutex_t *)malloc(
sizeof(pthread_mutex_t));
68 pthread_mutex_init((pthread_mutex_t *)c_os_mutex, &attr);
69 pthread_mutexattr_destroy(&attr);
71 #pragma error("no implementation of mutexes for this OS yet!")
82 if (!c_os_mutex)
return;
84 DeleteCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
86 #elif defined(__UNIX__)
87 pthread_mutex_destroy((pthread_mutex_t *)c_os_mutex);
90 #pragma error("no implementation of mutexes for this OS yet!")
97 if (!c_os_mutex)
return;
99 EnterCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
100 #elif defined(__UNIX__)
101 pthread_mutex_lock((pthread_mutex_t *)c_os_mutex);
103 #pragma error("no implementation of mutexes for this OS yet!")
109 if (!c_os_mutex)
return;
111 LeaveCriticalSection((LPCRITICAL_SECTION)c_os_mutex);
112 #elif defined(__UNIX__)
113 pthread_mutex_unlock((pthread_mutex_t *)c_os_mutex);
115 #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.