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

source code of glibc/sysdeps/nptl/internaltypes.h