| 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 | |
| 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 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <http://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #ifndef _INTERNALTYPES_H |
| 20 | #define _INTERNALTYPES_H 1 |
| 21 | |
| 22 | #include <stdint.h> |
| 23 | #include <atomic.h> |
| 24 | #include <endian.h> |
| 25 | |
| 26 | |
| 27 | struct pthread_attr |
| 28 | { |
| 29 | /* Scheduler parameters and priority. */ |
| 30 | struct sched_param schedparam; |
| 31 | int schedpolicy; |
| 32 | /* Various flags like detachstate, scope, etc. */ |
| 33 | int flags; |
| 34 | /* Size of guard area. */ |
| 35 | size_t guardsize; |
| 36 | /* Stack handling. */ |
| 37 | void *stackaddr; |
| 38 | size_t stacksize; |
| 39 | /* Affinity map. */ |
| 40 | cpu_set_t *cpuset; |
| 41 | size_t cpusetsize; |
| 42 | }; |
| 43 | |
| 44 | #define ATTR_FLAG_DETACHSTATE 0x0001 |
| 45 | #define ATTR_FLAG_NOTINHERITSCHED 0x0002 |
| 46 | #define ATTR_FLAG_SCOPEPROCESS 0x0004 |
| 47 | #define ATTR_FLAG_STACKADDR 0x0008 |
| 48 | #define ATTR_FLAG_OLDATTR 0x0010 |
| 49 | #define ATTR_FLAG_SCHED_SET 0x0020 |
| 50 | #define ATTR_FLAG_POLICY_SET 0x0040 |
| 51 | |
| 52 | |
| 53 | /* Mutex attribute data structure. */ |
| 54 | struct pthread_mutexattr |
| 55 | { |
| 56 | /* Identifier for the kind of mutex. |
| 57 | |
| 58 | Bit 31 is set if the mutex is to be shared between processes. |
| 59 | |
| 60 | Bit 0 to 30 contain one of the PTHREAD_MUTEX_ values to identify |
| 61 | the type of the mutex. */ |
| 62 | int mutexkind; |
| 63 | }; |
| 64 | |
| 65 | |
| 66 | /* Conditional variable attribute data structure. */ |
| 67 | struct pthread_condattr |
| 68 | { |
| 69 | /* Combination of values: |
| 70 | |
| 71 | Bit 0 : flag whether conditional variable will be |
| 72 | sharable between processes. |
| 73 | Bit 1-COND_CLOCK_BITS: Clock ID. COND_CLOCK_BITS is the number of bits |
| 74 | needed to represent the ID of the clock. */ |
| 75 | int value; |
| 76 | }; |
| 77 | #define COND_CLOCK_BITS 1 |
| 78 | |
| 79 | |
| 80 | /* Read-write lock variable attribute data structure. */ |
| 81 | struct pthread_rwlockattr |
| 82 | { |
| 83 | int lockkind; |
| 84 | int pshared; |
| 85 | }; |
| 86 | |
| 87 | |
| 88 | /* Barrier data structure. See pthread_barrier_wait for a description |
| 89 | of how these fields are used. */ |
| 90 | struct pthread_barrier |
| 91 | { |
| 92 | unsigned int in; |
| 93 | unsigned int current_round; |
| 94 | unsigned int count; |
| 95 | int shared; |
| 96 | unsigned int out; |
| 97 | }; |
| 98 | /* See pthread_barrier_wait for a description. */ |
| 99 | #define BARRIER_IN_THRESHOLD (UINT_MAX/2) |
| 100 | |
| 101 | |
| 102 | /* Barrier variable attribute data structure. */ |
| 103 | struct pthread_barrierattr |
| 104 | { |
| 105 | int pshared; |
| 106 | }; |
| 107 | |
| 108 | |
| 109 | /* Thread-local data handling. */ |
| 110 | struct pthread_key_struct |
| 111 | { |
| 112 | /* Sequence numbers. Even numbers indicated vacant entries. Note |
| 113 | that zero is even. We use uintptr_t to not require padding on |
| 114 | 32- and 64-bit machines. On 64-bit machines it helps to avoid |
| 115 | wrapping, too. */ |
| 116 | uintptr_t seq; |
| 117 | |
| 118 | /* Destructor for the data. */ |
| 119 | void (*destr) (void *); |
| 120 | }; |
| 121 | |
| 122 | /* Check whether an entry is unused. */ |
| 123 | #define KEY_UNUSED(p) (((p) & 1) == 0) |
| 124 | /* Check whether a key is usable. We cannot reuse an allocated key if |
| 125 | the sequence counter would overflow after the next destroy call. |
| 126 | This would mean that we potentially free memory for a key with the |
| 127 | same sequence. This is *very* unlikely to happen, A program would |
| 128 | have to create and destroy a key 2^31 times (on 32-bit platforms, |
| 129 | on 64-bit platforms that would be 2^63). If it should happen we |
| 130 | simply don't use this specific key anymore. */ |
| 131 | #define KEY_USABLE(p) (((uintptr_t) (p)) < ((uintptr_t) ((p) + 2))) |
| 132 | |
| 133 | |
| 134 | /* Handling of read-write lock data. */ |
| 135 | // XXX For now there is only one flag. Maybe more in future. |
| 136 | #define RWLOCK_RECURSIVE(rwlock) ((rwlock)->__data.__flags != 0) |
| 137 | |
| 138 | |
| 139 | /* Semaphore variable structure. */ |
| 140 | struct new_sem |
| 141 | { |
| 142 | #if __HAVE_64B_ATOMICS |
| 143 | /* The data field holds both value (in the least-significant 32 bits) and |
| 144 | nwaiters. */ |
| 145 | # if __BYTE_ORDER == __LITTLE_ENDIAN |
| 146 | # define SEM_VALUE_OFFSET 0 |
| 147 | # elif __BYTE_ORDER == __BIG_ENDIAN |
| 148 | # define SEM_VALUE_OFFSET 1 |
| 149 | # else |
| 150 | # error Unsupported byte order. |
| 151 | # endif |
| 152 | # define SEM_NWAITERS_SHIFT 32 |
| 153 | # define SEM_VALUE_MASK (~(unsigned int)0) |
| 154 | uint64_t data; |
| 155 | int private; |
| 156 | int pad; |
| 157 | #else |
| 158 | # define SEM_VALUE_SHIFT 1 |
| 159 | # define SEM_NWAITERS_MASK ((unsigned int)1) |
| 160 | unsigned int value; |
| 161 | int private; |
| 162 | int pad; |
| 163 | unsigned int nwaiters; |
| 164 | #endif |
| 165 | }; |
| 166 | |
| 167 | struct old_sem |
| 168 | { |
| 169 | unsigned int value; |
| 170 | }; |
| 171 | |
| 172 | |
| 173 | /* Compatibility type for old conditional variable interfaces. */ |
| 174 | typedef struct |
| 175 | { |
| 176 | pthread_cond_t *cond; |
| 177 | } pthread_cond_2_0_t; |
| 178 | |
| 179 | #endif /* internaltypes.h */ |
| 180 | |