malloc-machine.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Basic platform-independent macro definitions for mutexes,
  2. thread-specific data and parameters for malloc.
  3. Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #ifndef _MALLOC_MACHINE_H
  18. #define _MALLOC_MACHINE_H
  19. #undef thread_atfork_static
  20. #include <atomic.h>
  21. #include <bits/libc-lock.h>
  22. __libc_lock_define (typedef, mutex_t)
  23. #define mutex_init(m) __libc_lock_init (*(m))
  24. #define mutex_lock(m) __libc_lock_lock (*(m))
  25. #define mutex_trylock(m) __libc_lock_trylock (*(m))
  26. #define mutex_unlock(m) __libc_lock_unlock (*(m))
  27. /* This is defined by newer gcc version unique for each module. */
  28. extern void *__dso_handle __attribute__ ((__weak__));
  29. #include <fork.h>
  30. #define ATFORK_MEM static struct fork_handler atfork_mem
  31. #ifdef SHARED
  32. # define thread_atfork(prepare, parent, child) \
  33. atfork_mem.prepare_handler = prepare; \
  34. atfork_mem.parent_handler = parent; \
  35. atfork_mem.child_handler = child; \
  36. atfork_mem.dso_handle = __dso_handle; \
  37. atfork_mem.refcntr = 1; \
  38. __linkin_atfork (&atfork_mem)
  39. #else
  40. # define thread_atfork(prepare, parent, child) \
  41. atfork_mem.prepare_handler = prepare; \
  42. atfork_mem.parent_handler = parent; \
  43. atfork_mem.child_handler = child; \
  44. atfork_mem.dso_handle = &__dso_handle == NULL ? NULL : __dso_handle; \
  45. atfork_mem.refcntr = 1; \
  46. __linkin_atfork (&atfork_mem)
  47. #endif
  48. /* thread specific data for glibc */
  49. #include <bits/libc-tsd.h>
  50. typedef int tsd_key_t[1]; /* no key data structure, libc magic does it */
  51. __libc_tsd_define (static, void *, MALLOC) /* declaration/common definition */
  52. #define tsd_key_create(key, destr) ((void) (key))
  53. #define tsd_setspecific(key, data) __libc_tsd_set (void *, MALLOC, (data))
  54. #define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (void *, MALLOC))
  55. #include <sysdeps/generic/malloc-machine.h>
  56. #endif /* !defined(_MALLOC_MACHINE_H) */