From d440c3f50a918a932293ad98bcec96eaa4683222 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 4 Dec 2011 01:19:09 -0800 Subject: Reworked some things in the architecture, mainly exceptions and asserts. -) Removed Assert() -) Added AAssert(), IAssert(), RAssert(), TAssert() and Failure() -) Reworked all asserts in the code, and added meaningful messages to them. -) Changed the way the startup code is generated; BALAU_STARTUP is no longer necessary. --- src/Threads.cc | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/Threads.cc') diff --git a/src/Threads.cc b/src/Threads.cc index f6578ed..df19da2 100644 --- a/src/Threads.cc +++ b/src/Threads.cc @@ -17,11 +17,11 @@ Balau::Lock::Lock() { pthread_mutexattr_t attr; r = pthread_mutexattr_init(&attr); - Assert(r == 0); + RAssert(r == 0, "Couldn't initialize mutex attribute; r = %i", r); r = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - Assert(r == 0); + RAssert(r == 0, "Couldn't set mutex attribute; r = %i", r); r = pthread_mutex_init(&m_lock, &attr); - Assert(r == 0); + RAssert(r == 0, "Couldn't initialize mutex; r = %i", r); } void * Balau::ThreadHelper::threadProc(void * arg) { @@ -39,8 +39,10 @@ Balau::Thread::~Thread() { void * Balau::Thread::join() { void * r = NULL; - if (Atomic::CmpXChgBool(&m_joined, true, false)) + if (Atomic::CmpXChgBool(&m_joined, true, false)) { + threadExit(); pthread_join(m_thread, &r); + } return r; } @@ -49,9 +51,11 @@ void Balau::Thread::threadStart() { int r; r = pthread_attr_init(&attr); - Assert(r == 0); + RAssert(r == 0, "Couldn't initialize pthread attribute; r = %i", r); r = pthread_create(&m_thread, &attr, Balau::ThreadHelper::threadProc, this); - Assert(r == 0); + RAssert(r == 0, "Couldn't create pthread; r = %i", r); r = pthread_attr_destroy(&attr); - Assert(r == 0); + RAssert(r == 0, "Couldn't destroy pthread attribute; r = %i", r); } + +void Balau::Thread::threadExit() { } -- cgit v1.2.3