aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Carroll <thecarrolls@jiminger.com>2011-07-20 20:02:12 -0400
committerJim Carroll <thecarrolls@jiminger.com>2011-07-20 20:10:49 -0400
commit58a4276e76cded11e489e86dda6ef1edf38a5a8b (patch)
tree5a92a208681cc8c198292c115d87348d34561e46
parente48b66938c3788c8ed8a64db84c3ebb06a223fad (diff)
Fixed the use of assert so that it wont leave an "unused variable" warning when compiling for release.
-rw-r--r--xbmc/threads/Helpers.h12
-rw-r--r--xbmc/threads/platform/pthreads/Condition.h18
-rw-r--r--xbmc/threads/platform/pthreads/CriticalSection.h18
-rw-r--r--xbmc/threads/platform/pthreads/Implementation.cpp8
-rw-r--r--xbmc/threads/platform/pthreads/ThreadLocal.h12
-rw-r--r--xbmc/threads/platform/win/CriticalSection.h1
-rw-r--r--xbmc/threads/platform/win/ThreadLocal.h26
7 files changed, 38 insertions, 57 deletions
diff --git a/xbmc/threads/Helpers.h b/xbmc/threads/Helpers.h
index c8898e6e99..7d24220a13 100644
--- a/xbmc/threads/Helpers.h
+++ b/xbmc/threads/Helpers.h
@@ -37,3 +37,15 @@ namespace XbmcThreads
};
}
+
+#ifdef NDEBUG
+#define XBMC_ASSERT_TRUE(expression) assert( expression )
+#define XBMC_ASSERT_NOTEQUALS(compareTo,expression) assert( compareTo != expression )
+#define XBMC_ASSERT_EQUALS(compareTo,expression) assert( compareTo == expression )
+#define XBMC_ASSERT_ZERO(expression) assert( 0 == expression )
+#else
+#define XBMC_ASSERT_TRUE(expression) expression
+#define XBMC_ASSERT_NOTEQUALS(compareTo,expression) expression
+#define XBMC_ASSERT_EQUALS(compareTo,expression) expression
+#define XBMC_ASSERT_ZERO(expression) expression
+#endif
diff --git a/xbmc/threads/platform/pthreads/Condition.h b/xbmc/threads/platform/pthreads/Condition.h
index c573ba43b7..59433d33a9 100644
--- a/xbmc/threads/platform/pthreads/Condition.h
+++ b/xbmc/threads/platform/pthreads/Condition.h
@@ -44,20 +44,17 @@ namespace XbmcThreads
public:
inline ConditionVariable()
{
- int pthread_cond_init_result = pthread_cond_init(&cond,NULL);
- assert(pthread_cond_init_result == 0);
+ XBMC_ASSERT_ZERO(pthread_cond_init(&cond,NULL));
}
inline ~ConditionVariable()
{
- int pthread_cond_destroy_result = pthread_cond_destroy(&cond);
- assert(pthread_cond_destroy_result == 0);
+ XBMC_ASSERT_ZERO(pthread_cond_destroy(&cond));
}
inline void wait(CCriticalSection& lock)
{
- int pthread_cond_wait_result = pthread_cond_wait(&cond,&lock.get_underlying().mutex);
- assert(pthread_cond_wait_result == 0);
+ XBMC_ASSERT_ZERO(pthread_cond_wait(&cond,&lock.get_underlying().mutex));
}
inline bool wait(CCriticalSection& lock, unsigned long milliseconds)
@@ -65,8 +62,7 @@ namespace XbmcThreads
struct timeval tv;
struct timespec ts;
- int result = gettimeofday(&tv,NULL);
- assert(result == 0);
+ XBMC_ASSERT_ZERO(gettimeofday(&tv,NULL));
milliseconds += tv.tv_usec / 1000; // move the usecs onto milliseconds
ts.tv_sec = tv.tv_sec + (time_t)(milliseconds/1000);
@@ -81,14 +77,12 @@ namespace XbmcThreads
inline void notifyAll()
{
- int pthread_cond_broadcast_result = pthread_cond_broadcast(&cond);
- assert(pthread_cond_broadcast_result == 0);
+ XBMC_ASSERT_ZERO(pthread_cond_broadcast(&cond));
}
inline void notify()
{
- int pthread_cond_signal_result = pthread_cond_signal(&cond);
- assert(pthread_cond_signal_result == 0);
+ XBMC_ASSERT_ZERO(pthread_cond_signal(&cond));
}
};
diff --git a/xbmc/threads/platform/pthreads/CriticalSection.h b/xbmc/threads/platform/pthreads/CriticalSection.h
index 7414a9c8c6..0946879dd0 100644
--- a/xbmc/threads/platform/pthreads/CriticalSection.h
+++ b/xbmc/threads/platform/pthreads/CriticalSection.h
@@ -21,12 +21,12 @@
#pragma once
-#include "threads/Lockables.h"
-
#include <pthread.h>
-#include <assert.h>
#include <errno.h>
+#include "threads/Lockables.h"
+#include "threads/Helpers.h"
+
namespace XbmcThreads
{
@@ -45,26 +45,22 @@ namespace XbmcThreads
public:
inline RecursiveMutex()
{
- int pthread_mutex_init_result = pthread_mutex_init(&mutex,getRecusiveAttr());
- assert(pthread_mutex_init_result == 0);
+ XBMC_ASSERT_ZERO(pthread_mutex_init(&mutex,getRecusiveAttr()));
}
inline ~RecursiveMutex()
{
- int pthread_mutex_destroy_result = pthread_mutex_destroy(&mutex);
- assert(pthread_mutex_destroy_result == 0);
+ XBMC_ASSERT_ZERO(pthread_mutex_destroy(&mutex));
}
inline void lock()
{
- int pthread_mutex_lock_result = pthread_mutex_lock(&mutex);
- assert(pthread_mutex_lock_result == 0);
+ XBMC_ASSERT_ZERO(pthread_mutex_lock(&mutex));
}
inline void unlock()
{
- int pthread_mutex_unlock_result = pthread_mutex_unlock(&mutex);
- assert(pthread_mutex_unlock_result == 0);
+ XBMC_ASSERT_ZERO(pthread_mutex_unlock(&mutex));
}
inline bool try_lock()
diff --git a/xbmc/threads/platform/pthreads/Implementation.cpp b/xbmc/threads/platform/pthreads/Implementation.cpp
index 4f9f00832d..d87730aa52 100644
--- a/xbmc/threads/platform/pthreads/Implementation.cpp
+++ b/xbmc/threads/platform/pthreads/Implementation.cpp
@@ -21,8 +21,8 @@
#include "threads/Lockables.h"
#include "threads/platform/pthreads/CriticalSection.h"
+#include "threads/Helpers.h"
-#include <assert.h>
#include <pthread.h>
namespace XbmcThreads
@@ -37,10 +37,8 @@ namespace XbmcThreads
static bool alreadyCalled = false; // initialized to 0 in the data segment prior to startup init code running
if (!alreadyCalled)
{
- int pthread_mutexattr_result = pthread_mutexattr_init(&recursiveAttr);
- assert(pthread_mutexattr_result == 0);
- pthread_mutexattr_result = pthread_mutexattr_settype(&recursiveAttr,PTHREAD_MUTEX_RECURSIVE);
- assert(pthread_mutexattr_result == 0);
+ XBMC_ASSERT_ZERO(pthread_mutexattr_init(&recursiveAttr));
+ XBMC_ASSERT_ZERO(pthread_mutexattr_settype(&recursiveAttr,PTHREAD_MUTEX_RECURSIVE));
alreadyCalled = true;
}
return true; // note, we never call destroy.
diff --git a/xbmc/threads/platform/pthreads/ThreadLocal.h b/xbmc/threads/platform/pthreads/ThreadLocal.h
index 031c60e7e8..9be266645a 100644
--- a/xbmc/threads/platform/pthreads/ThreadLocal.h
+++ b/xbmc/threads/platform/pthreads/ThreadLocal.h
@@ -22,7 +22,8 @@
#pragma once
#include <pthread.h>
-#include <assert.h>
+
+#include "threads/Helpers.h"
namespace XbmcThreads
{
@@ -36,20 +37,17 @@ namespace XbmcThreads
public:
inline ThreadLocal()
{
- int pthread_key_create_result = pthread_key_create(&key,NULL);
- assert(pthread_key_create_result == 0);
+ XBMC_ASSERT_ZERO(pthread_key_create(&key,NULL));
}
inline ~ThreadLocal()
{
- int pthread_key_delete_result = pthread_key_delete(key);
- assert(pthread_key_delete_result == 0);
+ XBMC_ASSERT_ZERO(pthread_key_delete(key));
}
inline void set(T* val)
{
- int pthread_setspecific_result = pthread_setspecific(key,(void*)val);
- assert(pthread_setspecific_result == 0);
+ XBMC_ASSERT_ZERO(pthread_setspecific(key,(void*)val));
}
inline T* get()
diff --git a/xbmc/threads/platform/win/CriticalSection.h b/xbmc/threads/platform/win/CriticalSection.h
index f6c7503ca1..40701a9cb6 100644
--- a/xbmc/threads/platform/win/CriticalSection.h
+++ b/xbmc/threads/platform/win/CriticalSection.h
@@ -24,7 +24,6 @@
#include "threads/Lockables.h"
#include <windows.h>
-#include <assert.h>
namespace XbmcThreads
{
diff --git a/xbmc/threads/platform/win/ThreadLocal.h b/xbmc/threads/platform/win/ThreadLocal.h
index 018722d9cb..e770ff9f44 100644
--- a/xbmc/threads/platform/win/ThreadLocal.h
+++ b/xbmc/threads/platform/win/ThreadLocal.h
@@ -22,40 +22,24 @@
#pragma once
#include <windows.h>
-#include <assert.h>
namespace XbmcThreads
{
/**
- * A thin wrapper around pthreads thread specific storage
+ * A thin wrapper around windows thread specific storage
* functionality.
*/
template <typename T> class ThreadLocal
{
DWORD key;
public:
- inline ThreadLocal()
- {
- key = TlsAlloc();
- assert(key != TLS_OUT_OF_INDEXES);
- }
+ inline ThreadLocal() { XBMC_ASSERT_NOTEQUALS(TLS_OUT_OF_INDEXES,TlsAlloc()); }
- inline ~ThreadLocal()
- {
- BOOL tls_free_result = TlsFree(key);
- assert(tls_free_result);
- }
+ inline ~ThreadLocal() { XBMC_ASSERT_TRUE(TlsFree(key)); }
- inline void set(T* val)
- {
- BOOL tls_set_value_result = TlsSetValue(key,(LPVOID)val);
- assert(tls_set_value_result);
- }
+ inline void set(T* val) { XBMC_ASSERT_TRUE(TlsSetValue(key,(LPVOID)val)); }
- inline T* get()
- {
- return (T*)TlsGetValue(key);
- }
+ inline T* get() { return (T*)TlsGetValue(key); }
};
}