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.
This commit is contained in:
parent
82dd78d698
commit
d0b797e62c
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,10 +108,15 @@ int ThreadSemaphore::wait(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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -98,7 +98,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); }
|
||||
|
||||
|
@ -176,14 +176,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() { int s = pthread_join(mThread,NULL); assert(s==0); }
|
||||
|
||||
};
|
||||
|
||||
|
|
Reference in New Issue