chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / ports / sysdeps / unix / sysv / linux / hppa / linuxthreads / malloc-machine.h
1 /* HP-PARISC macro definitions for mutexes, thread-specific data 
2    and parameters for malloc.
3    Copyright (C) 2003 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
5    Contributed by Carlos O'Donell <carlos@baldric.uwo.ca>, 2003.
6    
7    The GNU C Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public
9    License as published by the Free Software Foundation; either
10    version 2.1 of the License, or (at your option) any later version.
11
12    The GNU C Library is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with the GNU C Library; if not, write to the Free
19    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20    02111-1307 USA.  */
21
22 #ifndef _MALLOC_MACHINE_H
23 #define _MALLOC_MACHINE_H
24
25 #undef thread_atfork_static
26
27 #include <atomic.h>
28 #include <bits/libc-lock.h>
29
30 __libc_lock_define (typedef, mutex_t)
31
32 /* Since our lock structure does not tolerate being initialized to zero, we must
33    modify the standard function calls made by malloc */
34 #  define mutex_init(m)         \
35         __libc_maybe_call (__pthread_mutex_init, (m, NULL), \
36                 (((m)->__m_lock.__spinlock = __LT_SPINLOCK_INIT),(*(int *)(m))) )
37 #  define mutex_lock(m)         \
38         __libc_maybe_call (__pthread_mutex_lock, (m), \
39                         (__load_and_clear(&((m)->__m_lock.__spinlock)), 0))
40 #  define mutex_trylock(m)      \
41         __libc_maybe_call (__pthread_mutex_trylock, (m), \
42                         (*(int *)(m) ? 1 : (__load_and_clear(&((m)->__m_lock.__spinlock)), 0)))
43 #  define mutex_unlock(m)       \
44         __libc_maybe_call (__pthread_mutex_unlock, (m), \
45                         (((m)->__m_lock.__spinlock = __LT_SPINLOCK_INIT), (*(int *)(m))) )
46         
47 /* This is defined by newer gcc version unique for each module.  */
48 extern void *__dso_handle __attribute__ ((__weak__));
49
50 #include <fork.h>
51
52 #ifdef SHARED
53 # define thread_atfork(prepare, parent, child) \
54    __register_atfork (prepare, parent, child, __dso_handle)
55 #else
56 # define thread_atfork(prepare, parent, child) \
57    __register_atfork (prepare, parent, child,                                 \
58                       &__dso_handle == NULL ? NULL : __dso_handle)
59 #endif
60
61 /* thread specific data for glibc */
62
63 #include <bits/libc-tsd.h>
64
65 typedef int tsd_key_t[1];       /* no key data structure, libc magic does it */
66 __libc_tsd_define (static, void *, MALLOC)      /* declaration/common definition */
67 #define tsd_key_create(key, destr)      ((void) (key))
68 #define tsd_setspecific(key, data)      __libc_tsd_set (void *, MALLOC, (data))
69 #define tsd_getspecific(key, vptr)      ((vptr) = __libc_tsd_get (void *, MALLOC))
70
71 #include <sysdeps/generic/malloc-machine.h>
72
73 #endif /* !defined(_MALLOC_MACHINE_H) */