Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8 from mdempsky/master

Add LIBCXXRT_WEAK_LOCKS config macro
CR by David
  • Loading branch information...
commit 564f47f1f8e04c62dc0cbec1c909594393c974b8 2 parents 5d697c8 + e80e018
cbergstrom authored
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/exception.cc
View
20 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)
Please sign in to comment.
Something went wrong with that request. Please try again.