12 #include "../stdafx.h"
17 #include "../safeguards.h"
37 self_destruct(self_destruct)
44 assert(pthread_self() == this->
thread);
52 assert(pthread_self() != this->
thread);
53 pthread_join(this->
thread, NULL);
82 pthread_detach(pthread_self());
91 if (thread != NULL) *thread = to;
109 pthread_mutexattr_init(&this->
attr);
110 pthread_mutexattr_settype(&this->
attr, PTHREAD_MUTEX_ERRORCHECK);
111 pthread_mutex_init(&this->
mutex, &this->
attr);
112 pthread_cond_init(&this->
condition, NULL);
117 int err = pthread_cond_destroy(&this->
condition);
118 assert(err != EBUSY);
119 err = pthread_mutex_destroy(&this->
mutex);
120 assert(err != EBUSY);
123 bool IsOwnedByCurrentThread()
const
125 return this->
owner == pthread_self();
131 if (this->IsOwnedByCurrentThread()) {
132 if (!allow_recursive) NOT_REACHED();
134 int err = pthread_mutex_lock(&this->
mutex);
137 this->
owner = pthread_self();
144 assert(this->IsOwnedByCurrentThread());
149 int err = pthread_mutex_unlock(&this->
mutex);
160 this->
owner = pthread_self();
166 int err = pthread_cond_signal(&this->
condition);