internaltypes.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Copyright (C) 2002, 2003, 2004, 2007 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. #ifndef _INTERNALTYPES_H
  16. #define _INTERNALTYPES_H 1
  17. #include <stdint.h>
  18. #include <sched.h>
  19. struct pthread_attr
  20. {
  21. /* Scheduler parameters and priority. */
  22. struct sched_param schedparam;
  23. int schedpolicy;
  24. /* Various flags like detachstate, scope, etc. */
  25. int flags;
  26. /* Size of guard area. */
  27. size_t guardsize;
  28. /* Stack handling. */
  29. void *stackaddr;
  30. size_t stacksize;
  31. /* Affinity map. */
  32. cpu_set_t *cpuset;
  33. size_t cpusetsize;
  34. };
  35. #define ATTR_FLAG_DETACHSTATE 0x0001
  36. #define ATTR_FLAG_NOTINHERITSCHED 0x0002
  37. #define ATTR_FLAG_SCOPEPROCESS 0x0004
  38. #define ATTR_FLAG_STACKADDR 0x0008
  39. #define ATTR_FLAG_OLDATTR 0x0010
  40. #define ATTR_FLAG_SCHED_SET 0x0020
  41. #define ATTR_FLAG_POLICY_SET 0x0040
  42. /* Mutex attribute data structure. */
  43. struct pthread_mutexattr
  44. {
  45. /* Identifier for the kind of mutex.
  46. Bit 31 is set if the mutex is to be shared between processes.
  47. Bit 0 to 30 contain one of the PTHREAD_MUTEX_ values to identify
  48. the type of the mutex. */
  49. int mutexkind;
  50. };
  51. /* Conditional variable attribute data structure. */
  52. struct pthread_condattr
  53. {
  54. /* Combination of values:
  55. Bit 0 : flag whether coditional variable will be shareable between
  56. processes.
  57. Bit 1-7: clock ID. */
  58. int value;
  59. };
  60. /* The __NWAITERS field is used as a counter and to house the number
  61. of bits for other purposes. COND_CLOCK_BITS is the number
  62. of bits needed to represent the ID of the clock. COND_NWAITERS_SHIFT
  63. is the number of bits reserved for other purposes like the clock. */
  64. #define COND_CLOCK_BITS 1
  65. #define COND_NWAITERS_SHIFT 1
  66. /* Read-write lock variable attribute data structure. */
  67. struct pthread_rwlockattr
  68. {
  69. int lockkind;
  70. int pshared;
  71. };
  72. /* Barrier data structure. */
  73. struct pthread_barrier
  74. {
  75. unsigned int curr_event;
  76. int lock;
  77. unsigned int left;
  78. unsigned int init_count;
  79. int private;
  80. };
  81. /* Barrier variable attribute data structure. */
  82. struct pthread_barrierattr
  83. {
  84. int pshared;
  85. };
  86. /* Thread-local data handling. */
  87. struct pthread_key_struct
  88. {
  89. /* Sequence numbers. Even numbers indicated vacant entries. Note
  90. that zero is even. We use uintptr_t to not require padding on
  91. 32- and 64-bit machines. On 64-bit machines it helps to avoid
  92. wrapping, too. */
  93. uintptr_t seq;
  94. /* Destructor for the data. */
  95. void (*destr) (void *);
  96. };
  97. /* Check whether an entry is unused. */
  98. #define KEY_UNUSED(p) (((p) & 1) == 0)
  99. /* Check whether a key is usable. We cannot reuse an allocated key if
  100. the sequence counter would overflow after the next destroy call.
  101. This would mean that we potentially free memory for a key with the
  102. same sequence. This is *very* unlikely to happen, A program would
  103. have to create and destroy a key 2^31 times (on 32-bit platforms,
  104. on 64-bit platforms that would be 2^63). If it should happen we
  105. simply don't use this specific key anymore. */
  106. #define KEY_USABLE(p) (((uintptr_t) (p)) < ((uintptr_t) ((p) + 2)))
  107. /* Handling of read-write lock data. */
  108. // XXX For now there is only one flag. Maybe more in future.
  109. #define RWLOCK_RECURSIVE(rwlock) ((rwlock)->__data.__flags != 0)
  110. /* Semaphore variable structure. */
  111. struct new_sem
  112. {
  113. unsigned int value;
  114. int private;
  115. unsigned long int nwaiters;
  116. };
  117. struct old_sem
  118. {
  119. unsigned int value;
  120. };
  121. /* Compatibility type for old conditional variable interfaces. */
  122. typedef struct
  123. {
  124. pthread_cond_t *cond;
  125. } pthread_cond_2_0_t;
  126. #endif /* internaltypes.h */