aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Chisnall <dchisnall@pathscale.com>2014-05-09 01:35:35 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-05-09 01:35:35 +0000
commit869078d31de37f79bb62819ba5a4ceb9d0dc9139 (patch)
tree2a0611d8af2304ffe230b0950b97c29aa594ce9d
parentf66374f99bb19926d8e3bd8f969160830d801cb3 (diff)
parentfef0612fb1e0f3d3004d2df2b637ed868f6d73e9 (diff)
downloadlibcxxrt-869078d31de37f79bb62819ba5a4ceb9d0dc9139.tar.gz
am fef0612f: Fix warnings about comparisons always evalutating to true when not using weak symbols for pthread functions.
* commit 'fef0612fb1e0f3d3004d2df2b637ed868f6d73e9': Fix warnings about comparisons always evalutating to true when not using weak symbols for pthread functions.
-rw-r--r--src/exception.cc26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/exception.cc b/src/exception.cc
index ecc50a7..c1cb243 100644
--- a/src/exception.cc
+++ b/src/exception.cc
@@ -41,9 +41,21 @@
#pragma weak pthread_once
#ifdef LIBCXXRT_WEAK_LOCKS
#pragma weak pthread_mutex_lock
+#define pthread_mutex_lock(mtx) do {\
+ if (pthread_mutex_lock) pthread_mutex_lock(mtx);\
+ } while(0)
#pragma weak pthread_mutex_unlock
+#define pthread_mutex_unlock(mtx) do {\
+ if (pthread_mutex_unlock) pthread_mutex_unlock(mtx);\
+ } while(0)
#pragma weak pthread_cond_signal
+#define pthread_cond_signal(cv) do {\
+ if (pthread_cond_signal) pthread_cond_signal(cv);\
+ } while(0)
#pragma weak pthread_cond_wait
+#define pthread_cond_wait(cv, mtx) do {\
+ if (pthread_cond_wait) pthread_cond_wait(cv, mtx);\
+ } while(0)
#endif
using namespace ABI_NAMESPACE;
@@ -448,7 +460,7 @@ static char *emergency_malloc(size_t size)
// Only 4 emergency buffers allowed per thread!
if (info->emergencyBuffersHeld > 3) { return 0; }
- if (pthread_mutex_lock) { pthread_mutex_lock(&emergency_malloc_lock); }
+ pthread_mutex_lock(&emergency_malloc_lock);
int buffer = -1;
while (buffer < 0)
{
@@ -459,7 +471,7 @@ static char *emergency_malloc(size_t size)
void *m = calloc(1, size);
if (0 != m)
{
- if (pthread_mutex_unlock) { pthread_mutex_unlock(&emergency_malloc_lock); }
+ pthread_mutex_unlock(&emergency_malloc_lock);
return (char*)m;
}
for (int i=0 ; i<16 ; i++)
@@ -476,10 +488,10 @@ static char *emergency_malloc(size_t size)
// of the emergency buffers.
if (buffer < 0)
{
- if (pthread_cond_wait) { pthread_cond_wait(&emergency_malloc_wait, &emergency_malloc_lock); }
+ pthread_cond_wait(&emergency_malloc_wait, &emergency_malloc_lock);
}
}
- if (pthread_mutex_unlock) { pthread_mutex_unlock(&emergency_malloc_lock); }
+ pthread_mutex_unlock(&emergency_malloc_lock);
info->emergencyBuffersHeld++;
return emergency_buffer + (1024 * buffer);
}
@@ -512,13 +524,13 @@ static void emergency_malloc_free(char *ptr)
memset((void*)ptr, 0, 1024);
// Signal the condition variable to wake up any threads that are blocking
// waiting for some space in the emergency buffer
- if (pthread_mutex_lock) { pthread_mutex_lock(&emergency_malloc_lock); }
+ pthread_mutex_lock(&emergency_malloc_lock);
// In theory, we don't need to do this with the lock held. In practice,
// our array of bools will probably be updated using 32-bit or 64-bit
// memory operations, so this update may clobber adjacent values.
buffer_allocated[buffer] = false;
- if (pthread_cond_signal) { pthread_cond_signal(&emergency_malloc_wait); }
- if (pthread_mutex_lock) { pthread_mutex_unlock(&emergency_malloc_lock); }
+ pthread_cond_signal(&emergency_malloc_wait);
+ pthread_mutex_unlock(&emergency_malloc_lock);
}
static char *alloc_or_die(size_t size)