mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-17 21:25:40 +00:00
(svn r20823) -Codechange: enable/add some error/sanity checking in the pthread code
This commit is contained in:
parent
410d48cbb8
commit
a15d179edf
@ -97,11 +97,14 @@ class ThreadMutex_pthread : public ThreadMutex {
|
|||||||
private:
|
private:
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
pthread_cond_t condition;
|
pthread_cond_t condition;
|
||||||
|
pthread_mutexattr_t attr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ThreadMutex_pthread()
|
ThreadMutex_pthread()
|
||||||
{
|
{
|
||||||
pthread_mutex_init(&this->mutex, NULL);
|
pthread_mutexattr_init(&this->attr);
|
||||||
|
pthread_mutexattr_settype(&this->attr, PTHREAD_MUTEX_ERRORCHECK);
|
||||||
|
pthread_mutex_init(&this->mutex, &this->attr);
|
||||||
pthread_cond_init(&this->condition, NULL);
|
pthread_cond_init(&this->condition, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,22 +118,26 @@ public:
|
|||||||
|
|
||||||
/* virtual */ void BeginCritical()
|
/* virtual */ void BeginCritical()
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&this->mutex);
|
int err = pthread_mutex_lock(&this->mutex);
|
||||||
|
assert(err == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ void EndCritical()
|
/* virtual */ void EndCritical()
|
||||||
{
|
{
|
||||||
pthread_mutex_unlock(&this->mutex);
|
int err = pthread_mutex_unlock(&this->mutex);
|
||||||
|
assert(err == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ void WaitForSignal()
|
/* virtual */ void WaitForSignal()
|
||||||
{
|
{
|
||||||
pthread_cond_wait(&this->condition, &this->mutex);
|
int err = pthread_cond_wait(&this->condition, &this->mutex);
|
||||||
|
assert(err == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* virtual */ void SendSignal()
|
/* virtual */ void SendSignal()
|
||||||
{
|
{
|
||||||
pthread_cond_signal(&this->condition);
|
int err = pthread_cond_signal(&this->condition);
|
||||||
|
assert(err == 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user