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 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)              \
00032   __libc_maybe_call2 (pthread_mutex_init, (m, NULL), (*(int *)(m) = 0))
00033 #define mutex_lock(m)              \
00034   __libc_maybe_call2 (pthread_mutex_lock, (m), ((*(int *)(m) = 1), 0))
00035 #define mutex_trylock(m)    \
00036   __libc_maybe_call2 (pthread_mutex_trylock, (m), \
00037                     (*(int *)(m) ? 1 : ((*(int *)(m) = 1), 0)))
00038 #define mutex_unlock(m)            \
00039   __libc_maybe_call2 (pthread_mutex_unlock, (m), (*(int *)(m) = 0))
00040 
00041 /* This is defined by newer gcc version unique for each module.  */
00042 extern void *__dso_handle __attribute__ ((__weak__));
00043 
00044 #include <fork.h>
00045 
00046 #ifdef SHARED
00047 # define thread_atfork(prepare, parent, child) \
00048    __register_atfork (prepare, parent, child, __dso_handle)
00049 #else
00050 # define thread_atfork(prepare, parent, child) \
00051    __register_atfork (prepare, parent, child,                               \
00052                     &__dso_handle == NULL ? NULL : __dso_handle)
00053 #endif
00054 
00055 /* thread specific data for glibc */
00056 
00057 #include <bits/libc-tsd.h>
00058 
00059 typedef int tsd_key_t[1];   /* no key data structure, libc magic does it */
00060 __libc_tsd_define (static, MALLOC) /* declaration/common definition */
00061 #define tsd_key_create(key, destr) ((void) (key))
00062 #define tsd_setspecific(key, data) __libc_tsd_set (MALLOC, (data))
00063 #define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (MALLOC))
00064 
00065 #include <sysdeps/generic/malloc-machine.h>
00066 
00067 #endif /* !defined(_MALLOC_MACHINE_H) */