summary refs log tree commit diff
path: root/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'malloc')
-rw-r--r--malloc/malloc.c4
-rw-r--r--malloc/obstack.h2
-rw-r--r--malloc/thread-m.h43
3 files changed, 33 insertions, 16 deletions
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 06fbf844f4..e5c3c64b15 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1750,11 +1750,11 @@ static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
 
 #endif
 
-static mchunkptr
 #if defined __GNUC__ && __GNUC__ >= 2
 /* This function is only called from one place, inline it.  */
 inline
 #endif
+static mchunkptr
 internal_function
 #if __STD_C
 mmap_chunk(size_t size)
@@ -2286,11 +2286,11 @@ arena *ar_ptr; mchunkptr p; INTERNAL_SIZE_T s;
   Main interface to sbrk (but see also malloc_trim).
 */
 
-static void
 #if defined __GNUC__ && __GNUC__ >= 2
 /* This function is called only from one place, inline it.  */
 inline
 #endif
+static void
 internal_function
 #if __STD_C
 malloc_extend_top(arena *ar_ptr, INTERNAL_SIZE_T nb)
diff --git a/malloc/obstack.h b/malloc/obstack.h
index 49492eb73c..e7ae6959e5 100644
--- a/malloc/obstack.h
+++ b/malloc/obstack.h
@@ -498,7 +498,7 @@ __extension__								\
  (unsigned) ((h)->chunk_limit - (h)->next_free)
 
 #define obstack_empty_p(h) \
- (h->chunk->prev == 0 && h->next_free - h->chunk->contents == 0)
+ ((h)->chunk->prev == 0 && (h)->next_free - (h)->chunk->contents == 0)
 
 /* Note that the call to _obstack_newchunk is enclosed in (..., 0)
    so that we can avoid having void expressions
diff --git a/malloc/thread-m.h b/malloc/thread-m.h
index 24d95dfb31..f9367c6782 100644
--- a/malloc/thread-m.h
+++ b/malloc/thread-m.h
@@ -19,7 +19,8 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-/* One out of _LIBC, USE_PTHREADS, USE_THR or USE_SPROC should be
+/* $Id$
+   One out of _LIBC, USE_PTHREADS, USE_THR or USE_SPROC should be
    defined, otherwise the token NO_THREADS and dummy implementations
    of the macros will be defined.  */
 
@@ -40,23 +41,18 @@ typedef pthread_t thread_id;
 typedef pthread_mutex_t	mutex_t;
 
 /* thread specific data */
-typedef pthread_key_t tsd_key_t;
+typedef void * tsd_key_t;
 
 #define MUTEX_INITIALIZER	PTHREAD_MUTEX_INITIALIZER
 
-static Void_t *malloc_key_data;
-
-#define tsd_key_create(key, destr) \
-  if (__pthread_key_create != NULL) {					      \
-    __pthread_key_create(key, destr);					      \
-  } else { *(key) = (tsd_key_t) 0; }
+#define tsd_key_create(key, destr) ( *(key) = NULL )
 #define tsd_setspecific(key, data) \
-  if (__pthread_setspecific != NULL) {					      \
-    __pthread_setspecific(key, data);					      \
-  } else { malloc_key_data = (Void_t *) data; }
+  if (__libc_internal_tsd_set != NULL) {				      \
+    __libc_internal_tsd_set(_LIBC_TSD_KEY_MALLOC, data);		      \
+  } else { (key) = (Void_t *) data; }
 #define tsd_getspecific(key, vptr) \
-  (vptr = (__pthread_getspecific != NULL				      \
-	   ? __pthread_getspecific(key) : malloc_key_data))
+  (vptr = (__libc_internal_tsd_get != NULL				      \
+	   ? __libc_internal_tsd_get(_LIBC_TSD_KEY_MALLOC) : (key)))
 
 #define mutex_init(m)		\
    (__pthread_mutex_init != NULL ? __pthread_mutex_init (m, NULL) : 0)
@@ -131,12 +127,33 @@ typedef pthread_mutex_t mutex_t;
 #define mutex_unlock(m)            pthread_mutex_unlock(m)
 
 /* thread specific data */
+#if defined(__sgi) || defined(USE_TSD_DATA_HACK)
+
+/* Hack for thread-specific data, e.g. on Irix 6.x.  We can't use
+   pthread_setspecific because that function calls malloc() itself.
+   The hack only works when pthread_t can be converted to an integral
+   type. */
+
+typedef void *tsd_key_t[256];
+#define tsd_key_create(key, destr) do { \
+  int i; \
+  for(i=0; i<256; i++) (*key)[i] = 0; \
+} while(0)
+#define tsd_setspecific(key, data) \
+ (key[(unsigned)pthread_self() % 256] = (data))
+#define tsd_getspecific(key, vptr) \
+ (vptr = key[(unsigned)pthread_self() % 256])
+
+#else
+
 typedef pthread_key_t tsd_key_t;
 
 #define tsd_key_create(key, destr) pthread_key_create(key, destr)
 #define tsd_setspecific(key, data) pthread_setspecific(key, data)
 #define tsd_getspecific(key, vptr) (vptr = pthread_getspecific(key))
 
+#endif
+
 /* at fork */
 #define thread_atfork(prepare, parent, child) \
                                    pthread_atfork(prepare, parent, child)