Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add LIBCXXRT_WEAK_LOCKS config macro #8

Merged
merged 2 commits into from

2 participants

Matthew Dempsky cbergstrom
Matthew Dempsky
Collaborator

No description provided.

Matthew Dempsky mdempsky 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.
b70baf1
cbergstrom cbergstrom merged commit 564f47f into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 2, 2013
  1. Matthew Dempsky

    Add a configuration define LIBCXXRT_WEAK_LOCKS to control whether the

    mdempsky authored
    pthread locking functions should be defined as weak symbols like the
    other pthread functions.
Commits on Jun 3, 2013
  1. Matthew Dempsky

    use braces consistently

    mdempsky authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/exception.cc
20 src/exception.cc
View
@@ -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)
Something went wrong with that request. Please try again.