12 #include "../stdafx.h"
17 #include "../safeguards.h"
38 self_destruct(self_destruct),
46 assert(pthread_self() == this->
thread);
54 assert(pthread_self() != this->
thread);
55 pthread_join(this->
thread, NULL);
66 #if defined(__GLIBC__)
67 #if __GLIBC_PREREQ(2, 12)
69 pthread_setname_np(pthread_self(), self->name);
92 pthread_detach(pthread_self());
101 if (thread != NULL) *thread = to;
119 pthread_mutexattr_init(&this->
attr);
120 pthread_mutexattr_settype(&this->
attr, PTHREAD_MUTEX_ERRORCHECK);
121 pthread_mutex_init(&this->
mutex, &this->
attr);
122 pthread_cond_init(&this->
condition, NULL);
127 int err = pthread_cond_destroy(&this->
condition);
128 assert(err != EBUSY);
129 err = pthread_mutex_destroy(&this->
mutex);
130 assert(err != EBUSY);
133 bool IsOwnedByCurrentThread()
const
135 return this->
owner == pthread_self();
141 if (this->IsOwnedByCurrentThread()) {
142 if (!allow_recursive) NOT_REACHED();
144 int err = pthread_mutex_lock(&this->
mutex);
147 this->
owner = pthread_self();
154 assert(this->IsOwnedByCurrentThread());
159 int err = pthread_mutex_unlock(&this->
mutex);
170 this->
owner = pthread_self();
176 int err = pthread_cond_signal(&this->
condition);