summaryrefslogtreecommitdiffstats
path: root/contrib/libcxxrt/exception.cc
diff options
context:
space:
mode:
authortheraven <theraven@FreeBSD.org>2012-03-14 00:09:36 +0000
committertheraven <theraven@FreeBSD.org>2012-03-14 00:09:36 +0000
commit7bd22d0949674b61e2c1a97cbb6caeeb5ab7fd19 (patch)
tree077f044b08d256dd8348f977fe56d18c08fccd78 /contrib/libcxxrt/exception.cc
parentd83b894ff4280333de5ef40496cfd061b515ba54 (diff)
parentbaa75b9984d33ea49ffb76a73507b64d879166cc (diff)
downloadFreeBSD-src-7bd22d0949674b61e2c1a97cbb6caeeb5ab7fd19.zip
FreeBSD-src-7bd22d0949674b61e2c1a97cbb6caeeb5ab7fd19.tar.gz
Import new versions of libcxxrt and libc++.
Please tests any C++ code you care about with -stdlib=libc++! Approved by: dim (mentor)
Diffstat (limited to 'contrib/libcxxrt/exception.cc')
-rw-r--r--contrib/libcxxrt/exception.cc70
1 files changed, 32 insertions, 38 deletions
diff --git a/contrib/libcxxrt/exception.cc b/contrib/libcxxrt/exception.cc
index 2da7454..8cbcb97 100644
--- a/contrib/libcxxrt/exception.cc
+++ b/contrib/libcxxrt/exception.cc
@@ -1,3 +1,29 @@
+/*
+ * Copyright 2010-2011 PathScale, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
+ * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include <stdlib.h>
#include <dlfcn.h>
#include <stdio.h>
@@ -12,12 +38,6 @@
#pragma weak pthread_setspecific
#pragma weak pthread_getspecific
#pragma weak pthread_once
-#pragma weak pthread_once
-#pragma weak pthread_cond_signal
-#pragma weak pthread_cond_wait
-#pragma weak pthread_mutex_lock
-#pragma weak pthread_mutex_unlock
-
using namespace ABI_NAMESPACE;
@@ -403,10 +423,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)
{
@@ -417,10 +434,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++)
@@ -437,24 +451,10 @@ static char *emergency_malloc(size_t size)
// of the emergency buffers.
if (buffer < 0)
{
- // If we don't have pthread_cond_wait, then there is only one
- // thread and it's already used all of the emergency buffers, so we
- // have no alternative but to die. Calling abort() instead of
- // terminate, because terminate can throw exceptions, which can
- // bring us back here and infinite loop.
- if (!pthread_cond_wait)
- {
- fputs("Terminating while out of memory trying to throw an exception",
- stderr);
- abort();
- }
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);
}
@@ -487,19 +487,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_mutex_unlock)
- {
- pthread_cond_signal(&emergency_malloc_wait);
- 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)
OpenPOWER on IntegriCloud