malloc-machine.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Basic platform-independent macro definitions for mutexes,
  2. thread-specific data and parameters for malloc.
  3. Copyright (C) 2003 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) \
  23. __libc_maybe_call2 (pthread_mutex_init, (m, NULL), (*(int *)(m) = 0))
  24. #define mutex_lock(m) \
  25. __libc_maybe_call2 (pthread_mutex_lock, (m), ((*(int *)(m) = 1), 0))
  26. #define mutex_trylock(m) \
  27. __libc_maybe_call2 (pthread_mutex_trylock, (m), \
  28. (*(int *)(m) ? 1 : ((*(int *)(m) = 1), 0)))
  29. #define mutex_unlock(m) \
  30. __libc_maybe_call2 (pthread_mutex_unlock, (m), (*(int *)(m) = 0))
  31. /* This is defined by newer gcc version unique for each module. */
  32. extern void *__dso_handle __attribute__ ((__weak__));
  33. #include <fork.h>
  34. #ifdef SHARED
  35. # define thread_atfork(prepare, parent, child) \
  36. __register_atfork (prepare, parent, child, __dso_handle)
  37. #else
  38. # define thread_atfork(prepare, parent, child) \
  39. __register_atfork (prepare, parent, child, \
  40. &__dso_handle == NULL ? NULL : __dso_handle)
  41. #endif
  42. /* thread specific data for glibc */
  43. #include <bits/libc-tsd.h>
  44. typedef int tsd_key_t[1]; /* no key data structure, libc magic does it */
  45. __libc_tsd_define (static, MALLOC) /* declaration/common definition */
  46. #define tsd_key_create(key, destr) ((void) (key))
  47. #define tsd_setspecific(key, data) __libc_tsd_set (MALLOC, (data))
  48. #define tsd_getspecific(key, vptr) ((vptr) = __libc_tsd_get (MALLOC))
  49. #include <sysdeps/generic/malloc-machine.h>
  50. #endif /* !defined(_MALLOC_MACHINE_H) */