libc_pthread_init.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (C) 2002,2003,2005,2006,2007,2009 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <unistd.h>
  17. #include <list.h>
  18. #include <fork.h>
  19. #include <dl-sysdep.h>
  20. #include <tls.h>
  21. #include <string.h>
  22. #include <pthreadP.h>
  23. #include <bits/libc-lock.h>
  24. #include <sysdep.h>
  25. #include <ldsodefs.h>
  26. #ifdef TLS_MULTIPLE_THREADS_IN_TCB
  27. void
  28. #else
  29. extern int __libc_multiple_threads attribute_hidden;
  30. int *
  31. #endif
  32. __libc_pthread_init (
  33. unsigned long int *ptr,
  34. void (*reclaim) (void),
  35. const struct pthread_functions *functions)
  36. {
  37. /* Remember the pointer to the generation counter in libpthread. */
  38. __fork_generation_pointer = ptr;
  39. /* Called by a child after fork. */
  40. __register_atfork (NULL, NULL, reclaim, NULL);
  41. #ifdef SHARED
  42. /* We copy the content of the variable pointed to by the FUNCTIONS
  43. parameter to one in libc.so since this means access to the array
  44. can be done with one memory access instead of two.
  45. */
  46. memcpy (&__libc_pthread_functions, functions,
  47. sizeof (__libc_pthread_functions));
  48. __libc_pthread_functions_init = 1;
  49. #endif
  50. #ifndef TLS_MULTIPLE_THREADS_IN_TCB
  51. return &__libc_multiple_threads;
  52. #endif
  53. }
  54. #ifdef SHARED
  55. #if 0
  56. void
  57. libc_freeres_fn (freeres_libptread)
  58. {
  59. if (__libc_pthread_functions_init)
  60. PTHFCT_CALL (ptr_freeres, ());
  61. }
  62. #endif
  63. #endif