fork.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright (C) 2002-2019 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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <lowlevellock.h>
  16. /* The fork generation counter, defined in libpthread. */
  17. extern unsigned long int __fork_generation attribute_hidden;
  18. /* Pointer to the fork generation counter in the thread library. */
  19. extern unsigned long int *__fork_generation_pointer attribute_hidden;
  20. /* Elements of the fork handler lists. */
  21. struct fork_handler
  22. {
  23. void (*prepare_handler) (void);
  24. void (*parent_handler) (void);
  25. void (*child_handler) (void);
  26. void *dso_handle;
  27. };
  28. /* Function to call to unregister fork handlers. */
  29. extern void __unregister_atfork (void *dso_handle) attribute_hidden;
  30. #define UNREGISTER_ATFORK(dso_handle) __unregister_atfork (dso_handle)
  31. enum __run_fork_handler_type
  32. {
  33. atfork_run_prepare,
  34. atfork_run_child,
  35. atfork_run_parent
  36. };
  37. /* Run the atfork handlers and lock/unlock the internal lock depending
  38. of the WHO argument:
  39. - atfork_run_prepare: run all the PREPARE_HANDLER in reverse order of
  40. insertion and locks the internal lock.
  41. - atfork_run_child: run all the CHILD_HANDLER and unlocks the internal
  42. lock.
  43. - atfork_run_parent: run all the PARENT_HANDLER and unlocks the internal
  44. lock. */
  45. extern void __run_fork_handlers (enum __run_fork_handler_type who)
  46. attribute_hidden;
  47. /* C library side function to register new fork handlers. */
  48. extern int __register_atfork (void (*__prepare) (void),
  49. void (*__parent) (void),
  50. void (*__child) (void),
  51. void *dso_handle);
  52. libc_hidden_proto (__register_atfork)