pthread_attr_init.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <errno.h>
  16. #include <string.h>
  17. #include <unistd.h>
  18. #include "pthreadP.h"
  19. #include <shlib-compat.h>
  20. struct pthread_attr *__attr_list;
  21. int __attr_list_lock = LLL_LOCK_INITIALIZER;
  22. int
  23. __pthread_attr_init_2_1 (pthread_attr_t *attr)
  24. {
  25. struct pthread_attr *iattr;
  26. ASSERT_TYPE_SIZE (pthread_attr_t, __SIZEOF_PTHREAD_ATTR_T);
  27. ASSERT_PTHREAD_INTERNAL_SIZE (pthread_attr_t, struct pthread_attr);
  28. /* Many elements are initialized to zero so let us do it all at
  29. once. This also takes care of clearing the bytes which are not
  30. internally used. */
  31. memset (attr, '\0', __SIZEOF_PTHREAD_ATTR_T);
  32. iattr = (struct pthread_attr *) attr;
  33. /* Default guard size specified by the standard. */
  34. iattr->guardsize = __getpagesize ();
  35. return 0;
  36. }
  37. versioned_symbol (libpthread, __pthread_attr_init_2_1, pthread_attr_init,
  38. GLIBC_2_1);
  39. #if SHLIB_COMPAT(libpthread, GLIBC_2_0, GLIBC_2_1)
  40. int
  41. __pthread_attr_init_2_0 (pthread_attr_t *attr)
  42. {
  43. /* This code is specific to the old LinuxThread code which has a too
  44. small pthread_attr_t definition. The struct looked like
  45. this: */
  46. struct old_attr
  47. {
  48. int detachstate;
  49. int schedpolicy;
  50. struct sched_param schedparam;
  51. int inheritsched;
  52. int scope;
  53. };
  54. struct pthread_attr *iattr;
  55. /* Many elements are initialized to zero so let us do it all at
  56. once. This also takes care of clearing the bytes which are not
  57. internally used. */
  58. memset (attr, '\0', sizeof (struct old_attr));
  59. iattr = (struct pthread_attr *) attr;
  60. iattr->flags |= ATTR_FLAG_OLDATTR;
  61. /* We cannot enqueue the attribute because that member is not in the
  62. old attribute structure. */
  63. return 0;
  64. }
  65. compat_symbol (libpthread, __pthread_attr_init_2_0, pthread_attr_init,
  66. GLIBC_2_0);
  67. #endif