Back to index

glibc  2.9
malloc-machine.h
Go to the documentation of this file.
00001 /* Basic platform-independent macro definitions for mutexes,
00002    thread-specific data and parameters for malloc.
00003    Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _MALLOC_MACHINE_H
00022 #define _MALLOC_MACHINE_H
00023 
00024 #undef thread_atfork_static
00025 
00026 #include <atomic.h>
00027 #include <bits/libc-lock.h>
00028 
00029 __libc_lock_define (typedef, mutex_t)
00030 
00031 #define mutex_init(m)              __libc_lock_init (*(m))
00032 #define mutex_lock(m)              __libc_lock_lock (*(m))
00033 #define mutex_trylock(m)    __libc_lock_trylock (*(m))
00034 #define mutex_unlock(m)            __libc_lock_unlock (*(m))
00035 
00036 /* This is defined by newer gcc version unique for each module.  */
00037 extern void *__dso_handle __attribute__ ((__weak__));
00038 
00039 #include <fork.h>
00040 
00041 #define ATFORK_MEM static struct fork_handler atfork_mem
00042 
00043 #ifdef SHARED
00044 # define thread_atfork(prepare, parent, child) \
00045   atfork_mem.prepare_handler = prepare;                                     \
00046   atfork_mem.parent_handler = parent;                                       \
00047   atfork_mem.child_handler = child;                                         \
00048   atfork_mem.dso_handle = __dso_handle;                                     \
00049   atfork_mem.refcntr = 1;                                            \
00050   __linkin_atfork (&atfork_mem)
00051 #else
00052 # define thread_atfork(prepare, parent, child) \
00053   atfork_mem.prepare_handler = prepare;                                     \
00054   atfork_mem.parent_handler = parent;                                       \
00055   atfork_mem.child_handler = child;                                         \
00056   atfork_mem.dso_handle = &__dso_handle == NULL ? NULL : __dso_handle;             \
00057   atfork_mem.refcntr = 1;                                            \
00058   __linkin_atfork (&atfork_mem)
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, void *, MALLOC)       /* declaration/common definition */
00067 #define tsd_key_create(key, destr) ((void) (key))
00068 #define tsd_setspecific(key, data) __libc_tsd_set (void *, MALLOC, (data))
00069 #define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (void *, MALLOC))
00070 
00071 #include <sysdeps/generic/malloc-machine.h>
00072 
00073 #endif /* !defined(_MALLOC_MACHINE_H) */