Back to index

glibc  2.9
malloc-machine.h
Go to the documentation of this file.
00001 /* HP-PARISC macro definitions for mutexes, thread-specific data 
00002    and parameters for malloc.
00003    Copyright (C) 2003 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Contributed by Carlos O'Donell <carlos@baldric.uwo.ca>, 2003.
00006    
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #ifndef _MALLOC_MACHINE_H
00023 #define _MALLOC_MACHINE_H
00024 
00025 #undef thread_atfork_static
00026 
00027 #include <atomic.h>
00028 #include <bits/libc-lock.h>
00029 
00030 __libc_lock_define (typedef, mutex_t)
00031 
00032 /* Since our lock structure does not tolerate being initialized to zero, we must
00033    modify the standard function calls made by malloc */
00034 #  define mutex_init(m)            \
00035        __libc_maybe_call (__pthread_mutex_init, (m, NULL), \
00036               (((m)->__m_lock.__spinlock = __LT_SPINLOCK_INIT),(*(int *)(m))) )
00037 #  define mutex_lock(m)            \
00038        __libc_maybe_call (__pthread_mutex_lock, (m), \
00039                      (__load_and_clear(&((m)->__m_lock.__spinlock)), 0))
00040 #  define mutex_trylock(m)  \
00041        __libc_maybe_call (__pthread_mutex_trylock, (m), \
00042                      (*(int *)(m) ? 1 : (__load_and_clear(&((m)->__m_lock.__spinlock)), 0)))
00043 #  define mutex_unlock(m)   \
00044        __libc_maybe_call (__pthread_mutex_unlock, (m), \
00045                      (((m)->__m_lock.__spinlock = __LT_SPINLOCK_INIT), (*(int *)(m))) )
00046        
00047 /* This is defined by newer gcc version unique for each module.  */
00048 extern void *__dso_handle __attribute__ ((__weak__));
00049 
00050 #include <fork.h>
00051 
00052 #ifdef SHARED
00053 # define thread_atfork(prepare, parent, child) \
00054    __register_atfork (prepare, parent, child, __dso_handle)
00055 #else
00056 # define thread_atfork(prepare, parent, child) \
00057    __register_atfork (prepare, parent, child,                               \
00058                     &__dso_handle == NULL ? NULL : __dso_handle)
00059 #endif
00060 
00061 /* thread specific data for glibc */
00062 
00063 #include <bits/libc-tsd.h>
00064 
00065 typedef int tsd_key_t[1];   /* no key data structure, libc magic does it */
00066 __libc_tsd_define (static, MALLOC) /* declaration/common definition */
00067 #define tsd_key_create(key, destr) ((void) (key))
00068 #define tsd_setspecific(key, data) __libc_tsd_set (MALLOC, (data))
00069 #define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (MALLOC))
00070 
00071 #include <sysdeps/generic/malloc-machine.h>
00072 
00073 #endif /* !defined(_MALLOC_MACHINE_H) */