1/* Common threading primitives definitions for both POSIX and C11.
2 Copyright (C) 2017-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 <https://www.gnu.org/licenses/>. */
18
19#ifndef _THREAD_SHARED_TYPES_H
20#define _THREAD_SHARED_TYPES_H 1
21
22/* Arch-specific definitions. Each architecture must define the following
23 macros to define the expected sizes of pthread data types:
24
25 __SIZEOF_PTHREAD_ATTR_T - size of pthread_attr_t.
26 __SIZEOF_PTHREAD_MUTEX_T - size of pthread_mutex_t.
27 __SIZEOF_PTHREAD_MUTEXATTR_T - size of pthread_mutexattr_t.
28 __SIZEOF_PTHREAD_COND_T - size of pthread_cond_t.
29 __SIZEOF_PTHREAD_CONDATTR_T - size of pthread_condattr_t.
30 __SIZEOF_PTHREAD_RWLOCK_T - size of pthread_rwlock_t.
31 __SIZEOF_PTHREAD_RWLOCKATTR_T - size of pthread_rwlockattr_t.
32 __SIZEOF_PTHREAD_BARRIER_T - size of pthread_barrier_t.
33 __SIZEOF_PTHREAD_BARRIERATTR_T - size of pthread_barrierattr_t.
34
35 The additional macro defines any constraint for the lock alignment
36 inside the thread structures:
37
38 __LOCK_ALIGNMENT - for internal lock/futex usage.
39
40 Same idea but for the once locking primitive:
41
42 __ONCE_ALIGNMENT - for pthread_once_t/once_flag definition. */
43
44#include <bits/pthreadtypes-arch.h>
45
46#include <bits/atomic_wide_counter.h>
47
48
49/* Common definition of pthread_mutex_t. */
50
51typedef struct __pthread_internal_list
52{
53 struct __pthread_internal_list *__prev;
54 struct __pthread_internal_list *__next;
55} __pthread_list_t;
56
57typedef struct __pthread_internal_slist
58{
59 struct __pthread_internal_slist *__next;
60} __pthread_slist_t;
61
62/* Arch-specific mutex definitions. A generic implementation is provided
63 by sysdeps/nptl/bits/struct_mutex.h. If required, an architecture
64 can override it by defining:
65
66 1. struct __pthread_mutex_s (used on both pthread_mutex_t and mtx_t
67 definition). It should contains at least the internal members
68 defined in the generic version.
69
70 2. __LOCK_ALIGNMENT for any extra attribute for internal lock used with
71 atomic operations.
72
73 3. The macro __PTHREAD_MUTEX_INITIALIZER used for static initialization.
74 It should initialize the mutex internal flag. */
75
76#include <bits/struct_mutex.h>
77
78/* Arch-sepecific read-write lock definitions. A generic implementation is
79 provided by struct_rwlock.h. If required, an architecture can override it
80 by defining:
81
82 1. struct __pthread_rwlock_arch_t (used on pthread_rwlock_t definition).
83 It should contain at least the internal members defined in the
84 generic version.
85
86 2. The macro __PTHREAD_RWLOCK_INITIALIZER used for static initialization.
87 It should initialize the rwlock internal type. */
88
89#include <bits/struct_rwlock.h>
90
91
92/* Common definition of pthread_cond_t. */
93
94struct __pthread_cond_s
95{
96 __atomic_wide_counter __wseq;
97 __atomic_wide_counter __g1_start;
98 unsigned int __g_refs[2] __LOCK_ALIGNMENT;
99 unsigned int __g_size[2];
100 unsigned int __g1_orig_size;
101 unsigned int __wrefs;
102 unsigned int __g_signals[2];
103};
104
105typedef unsigned int __tss_t;
106typedef unsigned long int __thrd_t;
107
108typedef struct
109{
110 int __data __ONCE_ALIGNMENT;
111} __once_flag;
112
113#define __ONCE_FLAG_INIT { 0 }
114
115#endif /* _THREAD_SHARED_TYPES_H */
116