| 1 | /* Common threading primitives definitions for both POSIX and C11. | 
| 2 |    Copyright (C) 2017-2018 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 |    <http://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 |    Also, the following macros must be define for internal pthread_mutex_t | 
| 36 |    struct definitions (struct __pthread_mutex_s): | 
| 37 |  | 
| 38 |    __PTHREAD_COMPAT_PADDING_MID   - any additional members after 'kind' | 
| 39 | 				    and before '__spin' (for 64 bits) or | 
| 40 | 				    '__nusers' (for 32 bits). | 
| 41 |    __PTHREAD_COMPAT_PADDING_END   - any additional members at the end of | 
| 42 | 				    the internal structure. | 
| 43 |    __PTHREAD_MUTEX_LOCK_ELISION   - 1 if the architecture supports lock | 
| 44 | 				    elision or 0 otherwise. | 
| 45 |    __PTHREAD_MUTEX_NUSERS_AFTER_KIND - control where to put __nusers.  The | 
| 46 | 				       preferred value for new architectures | 
| 47 | 				       is 0. | 
| 48 |    __PTHREAD_MUTEX_USE_UNION      - control whether internal __spins and | 
| 49 | 				    __list will be place inside a union for | 
| 50 | 				    linuxthreads compatibility. | 
| 51 | 				    The preferred value for new architectures | 
| 52 | 				    is 0. | 
| 53 |  | 
| 54 |    For a new port the preferred values for the required defines are: | 
| 55 |  | 
| 56 |    #define __PTHREAD_COMPAT_PADDING_MID | 
| 57 |    #define __PTHREAD_COMPAT_PADDING_END | 
| 58 |    #define __PTHREAD_MUTEX_LOCK_ELISION         0 | 
| 59 |    #define __PTHREAD_MUTEX_NUSERS_AFTER_KIND    0 | 
| 60 |    #define __PTHREAD_MUTEX_USE_UNION            0 | 
| 61 |  | 
| 62 |    __PTHREAD_MUTEX_LOCK_ELISION can be set to 1 if the hardware plans to | 
| 63 |    eventually support lock elision using transactional memory. | 
| 64 |  | 
| 65 |    The additional macro defines any constraint for the lock alignment | 
| 66 |    inside the thread structures: | 
| 67 |  | 
| 68 |    __LOCK_ALIGNMENT - for internal lock/futex usage. | 
| 69 |  | 
| 70 |    Same idea but for the once locking primitive: | 
| 71 |  | 
| 72 |    __ONCE_ALIGNMENT - for pthread_once_t/once_flag definition. | 
| 73 |  | 
| 74 |    And finally the internal pthread_rwlock_t (struct __pthread_rwlock_arch_t) | 
| 75 |    must be defined. | 
| 76 |  */ | 
| 77 | #include <bits/pthreadtypes-arch.h> | 
| 78 |  | 
| 79 | /* Common definition of pthread_mutex_t. */ | 
| 80 |  | 
| 81 | #if !__PTHREAD_MUTEX_USE_UNION | 
| 82 | typedef struct __pthread_internal_list | 
| 83 | { | 
| 84 |   struct __pthread_internal_list *__prev; | 
| 85 |   struct __pthread_internal_list *__next; | 
| 86 | } __pthread_list_t; | 
| 87 | #else | 
| 88 | typedef struct __pthread_internal_slist | 
| 89 | { | 
| 90 |   struct __pthread_internal_slist *__next; | 
| 91 | } __pthread_slist_t; | 
| 92 | #endif | 
| 93 |  | 
| 94 | /* Lock elision support.  */ | 
| 95 | #if __PTHREAD_MUTEX_LOCK_ELISION | 
| 96 | # if !__PTHREAD_MUTEX_USE_UNION | 
| 97 | #  define __PTHREAD_SPINS_DATA	\ | 
| 98 |   short __spins;		\ | 
| 99 |   short __elision | 
| 100 | #  define __PTHREAD_SPINS             0, 0 | 
| 101 | # else | 
| 102 | #  define __PTHREAD_SPINS_DATA	\ | 
| 103 |   struct			\ | 
| 104 |   {				\ | 
| 105 |     short __espins;		\ | 
| 106 |     short __eelision;		\ | 
| 107 |   } __elision_data | 
| 108 | #  define __PTHREAD_SPINS         { 0, 0 } | 
| 109 | #  define __spins __elision_data.__espins | 
| 110 | #  define __elision __elision_data.__eelision | 
| 111 | # endif | 
| 112 | #else | 
| 113 | # define __PTHREAD_SPINS_DATA int __spins | 
| 114 | /* Mutex __spins initializer used by PTHREAD_MUTEX_INITIALIZER.  */ | 
| 115 | # define __PTHREAD_SPINS 0 | 
| 116 | #endif | 
| 117 |  | 
| 118 | struct __pthread_mutex_s | 
| 119 | { | 
| 120 |   int __lock __LOCK_ALIGNMENT; | 
| 121 |   unsigned int __count; | 
| 122 |   int __owner; | 
| 123 | #if !__PTHREAD_MUTEX_NUSERS_AFTER_KIND | 
| 124 |   unsigned int __nusers; | 
| 125 | #endif | 
| 126 |   /* KIND must stay at this position in the structure to maintain | 
| 127 |      binary compatibility with static initializers.  */ | 
| 128 |   int __kind; | 
| 129 |   __PTHREAD_COMPAT_PADDING_MID | 
| 130 | #if __PTHREAD_MUTEX_NUSERS_AFTER_KIND | 
| 131 |   unsigned int __nusers; | 
| 132 | #endif | 
| 133 | #if !__PTHREAD_MUTEX_USE_UNION | 
| 134 |   __PTHREAD_SPINS_DATA; | 
| 135 |   __pthread_list_t __list; | 
| 136 | # define __PTHREAD_MUTEX_HAVE_PREV      1 | 
| 137 | #else | 
| 138 |   __extension__ union | 
| 139 |   { | 
| 140 |     __PTHREAD_SPINS_DATA; | 
| 141 |     __pthread_slist_t __list; | 
| 142 |   }; | 
| 143 | # define __PTHREAD_MUTEX_HAVE_PREV      0 | 
| 144 | #endif | 
| 145 |   __PTHREAD_COMPAT_PADDING_END | 
| 146 | }; | 
| 147 |  | 
| 148 |  | 
| 149 | /* Common definition of pthread_cond_t. */ | 
| 150 |  | 
| 151 | struct __pthread_cond_s | 
| 152 | { | 
| 153 |   __extension__ union | 
| 154 |   { | 
| 155 |     __extension__ unsigned long long int __wseq; | 
| 156 |     struct | 
| 157 |     { | 
| 158 |       unsigned int __low; | 
| 159 |       unsigned int __high; | 
| 160 |     } __wseq32; | 
| 161 |   }; | 
| 162 |   __extension__ union | 
| 163 |   { | 
| 164 |     __extension__ unsigned long long int __g1_start; | 
| 165 |     struct | 
| 166 |     { | 
| 167 |       unsigned int __low; | 
| 168 |       unsigned int __high; | 
| 169 |     } __g1_start32; | 
| 170 |   }; | 
| 171 |   unsigned int __g_refs[2] __LOCK_ALIGNMENT; | 
| 172 |   unsigned int __g_size[2]; | 
| 173 |   unsigned int __g1_orig_size; | 
| 174 |   unsigned int __wrefs; | 
| 175 |   unsigned int __g_signals[2]; | 
| 176 | }; | 
| 177 |  | 
| 178 | #endif /* _THREAD_SHARED_TYPES_H  */ | 
| 179 |  |