malloc-machine.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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, see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef _MALLOC_MACHINE_H
  17. #define _MALLOC_MACHINE_H
  18. #undef thread_atfork_static
  19. #include <atomic.h>
  20. #include <bits/libc-lock.h>
  21. __libc_lock_define (typedef, mutex_t)
  22. #define mutex_init(m) __libc_lock_init (*(m))
  23. #define mutex_lock(m) __libc_lock_lock (*(m))
  24. #define mutex_trylock(m) __libc_lock_trylock (*(m))
  25. #define mutex_unlock(m) __libc_lock_unlock (*(m))
  26. /* This is defined by newer gcc version unique for each module. */
  27. extern void *__dso_handle __attribute__ ((__weak__));
  28. #include <fork.h>
  29. #define ATFORK_MEM static struct fork_handler atfork_mem
  30. #ifdef SHARED
  31. # define thread_atfork(prepare, parent, child) \
  32. atfork_mem.prepare_handler = prepare; \
  33. atfork_mem.parent_handler = parent; \
  34. atfork_mem.child_handler = child; \
  35. atfork_mem.dso_handle = __dso_handle; \
  36. atfork_mem.refcntr = 1; \
  37. __linkin_atfork (&atfork_mem)
  38. #else
  39. # define thread_atfork(prepare, parent, child) \
  40. atfork_mem.prepare_handler = prepare; \
  41. atfork_mem.parent_handler = parent; \
  42. atfork_mem.child_handler = child; \
  43. atfork_mem.dso_handle = &__dso_handle == NULL ? NULL : __dso_handle; \
  44. atfork_mem.refcntr = 1; \
  45. __linkin_atfork (&atfork_mem)
  46. #endif
  47. /* thread specific data for glibc */
  48. #include <bits/libc-tsd.h>
  49. typedef int tsd_key_t[1]; /* no key data structure, libc magic does it */
  50. __libc_tsd_define (static, void *, MALLOC) /* declaration/common definition */
  51. #define tsd_key_create(key, destr) ((void) (key))
  52. #define tsd_setspecific(key, data) __libc_tsd_set (void *, MALLOC, (data))
  53. #define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (void *, MALLOC))
  54. #include <sysdeps/generic/malloc-machine.h>
  55. #endif /* !defined(_MALLOC_MACHINE_H) */