aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcbergstrom <sjsdfkdjdjd@github.com>2014-05-09 01:35:34 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-05-09 01:35:34 +0000
commitb0db0c776a729b5ccaaceec8e1a7609dc4365e6c (patch)
tree5346fc3703d7588ca72048ebff3d11e3c5627d2b
parent364082c2469aae2a932463a7fc591339083817cd (diff)
parent564f47f1f8e04c62dc0cbec1c909594393c974b8 (diff)
downloadlibcxxrt-b0db0c776a729b5ccaaceec8e1a7609dc4365e6c.tar.gz
am 564f47f1: Merge pull request #8 from mdempsky/master
* commit '564f47f1f8e04c62dc0cbec1c909594393c974b8': use braces consistently Add a configuration define LIBCXXRT_WEAK_LOCKS to control whether the pthread locking functions should be defined as weak symbols like the other pthread functions.
-rw-r--r--src/exception.cc20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/exception.cc b/src/exception.cc
index 343d69f..ecc50a7 100644
--- a/src/exception.cc
+++ b/src/exception.cc
@@ -39,6 +39,12 @@
#pragma weak pthread_setspecific
#pragma weak pthread_getspecific
#pragma weak pthread_once
+#ifdef LIBCXXRT_WEAK_LOCKS
+#pragma weak pthread_mutex_lock
+#pragma weak pthread_mutex_unlock
+#pragma weak pthread_cond_signal
+#pragma weak pthread_cond_wait
+#endif
using namespace ABI_NAMESPACE;
@@ -442,7 +448,7 @@ static char *emergency_malloc(size_t size)
// Only 4 emergency buffers allowed per thread!
if (info->emergencyBuffersHeld > 3) { return 0; }
- pthread_mutex_lock(&emergency_malloc_lock);
+ if (pthread_mutex_lock) { pthread_mutex_lock(&emergency_malloc_lock); }
int buffer = -1;
while (buffer < 0)
{
@@ -453,7 +459,7 @@ static char *emergency_malloc(size_t size)
void *m = calloc(1, size);
if (0 != m)
{
- pthread_mutex_unlock(&emergency_malloc_lock);
+ if (pthread_mutex_unlock) { pthread_mutex_unlock(&emergency_malloc_lock); }
return (char*)m;
}
for (int i=0 ; i<16 ; i++)
@@ -470,10 +476,10 @@ static char *emergency_malloc(size_t size)
// of the emergency buffers.
if (buffer < 0)
{
- pthread_cond_wait(&emergency_malloc_wait, &emergency_malloc_lock);
+ if (pthread_cond_wait) { pthread_cond_wait(&emergency_malloc_wait, &emergency_malloc_lock); }
}
}
- pthread_mutex_unlock(&emergency_malloc_lock);
+ if (pthread_mutex_unlock) { pthread_mutex_unlock(&emergency_malloc_lock); }
info->emergencyBuffersHeld++;
return emergency_buffer + (1024 * buffer);
}
@@ -506,13 +512,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
- pthread_mutex_lock(&emergency_malloc_lock);
+ if (pthread_mutex_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;
- pthread_cond_signal(&emergency_malloc_wait);
- pthread_mutex_unlock(&emergency_malloc_lock);
+ if (pthread_cond_signal) { pthread_cond_signal(&emergency_malloc_wait); }
+ if (pthread_mutex_lock) { pthread_mutex_unlock(&emergency_malloc_lock); }
}
static char *alloc_or_die(size_t size)