Don't put real code into assert().
If you compile with optimization and NDEBUG is defined, then the whole assert() is replaced with ((void) 0) and your code is not executed at all.
Don't assert() on pthread_join() return value. If thread was not started yet, then pthread_join() will fail, but it's ok for us.
(cherry picked from commit d0b797e62c
, 21a84dcec9cdf25657bba5c221aac9d4bb81d8b3, 8ed37a1f36e1b1266728647e715f95a28df3f900)
This commit is contained in:
parent
f24e148432
commit
410d42eda0
|
@ -72,16 +72,17 @@ void unlockCerr()
|
|||
|
||||
Mutex::Mutex()
|
||||
{
|
||||
assert(!pthread_mutexattr_init(&mAttribs));
|
||||
assert(!pthread_mutexattr_settype(&mAttribs,PTHREAD_MUTEX_RECURSIVE));
|
||||
assert(!pthread_mutex_init(&mMutex,&mAttribs));
|
||||
pthread_mutexattr_init(&mAttribs);
|
||||
int s = pthread_mutexattr_settype(&mAttribs,PTHREAD_MUTEX_RECURSIVE);
|
||||
assert(s==0);
|
||||
pthread_mutex_init(&mMutex,&mAttribs);
|
||||
}
|
||||
|
||||
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
pthread_mutex_destroy(&mMutex);
|
||||
assert(!pthread_mutexattr_destroy(&mAttribs));
|
||||
pthread_mutexattr_destroy(&mAttribs);
|
||||
}
|
||||
|
||||
|
||||
|
@ -98,10 +99,15 @@ void Signal::wait(Mutex& wMutex, unsigned timeout) const
|
|||
|
||||
void Thread::start(void *(*task)(void*), void *arg)
|
||||
{
|
||||
int s;
|
||||
assert(mThread==((pthread_t)0));
|
||||
assert(!pthread_attr_init(&mAttrib));
|
||||
assert(!pthread_attr_setstacksize(&mAttrib, mStackSize));
|
||||
assert(!pthread_create(&mThread, &mAttrib, task, arg));
|
||||
|
||||
s = pthread_attr_init(&mAttrib);
|
||||
assert(s == 0);
|
||||
s = pthread_attr_setstacksize(&mAttrib, mStackSize);
|
||||
assert(s == 0);
|
||||
s = pthread_create(&mThread, &mAttrib, task, arg);
|
||||
assert(s == 0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ class Signal {
|
|||
|
||||
public:
|
||||
|
||||
Signal() { assert(!pthread_cond_init(&mSignal,NULL)); }
|
||||
Signal() { int s = pthread_cond_init(&mSignal,NULL); assert(s == 0); }
|
||||
|
||||
~Signal() { pthread_cond_destroy(&mSignal); }
|
||||
|
||||
|
@ -145,14 +145,14 @@ class Thread {
|
|||
Destroy the Thread.
|
||||
It should be stopped and joined.
|
||||
*/
|
||||
~Thread() { assert(!pthread_attr_destroy(&mAttrib)); }
|
||||
~Thread() { int s = pthread_attr_destroy(&mAttrib); assert(s==0); }
|
||||
|
||||
|
||||
/** Start the thread on a task. */
|
||||
void start(void *(*task)(void*), void *arg);
|
||||
|
||||
/** Join a thread that will stop on its own. */
|
||||
void join() { assert(!pthread_join(mThread,NULL)); }
|
||||
void join() { pthread_join(mThread,NULL); }
|
||||
|
||||
};
|
||||
|
||||
|
|
Reference in New Issue