1 1.1 mrg /* Threads compatibility routines for libgcc2 and libobjc. */ 2 1.1 mrg /* Compile this one with gcc. */ 3 1.1.1.3 mrg /* Copyright (C) 2019-2024 Free Software Foundation, Inc. 4 1.1 mrg 5 1.1 mrg This file is part of GCC. 6 1.1 mrg 7 1.1 mrg GCC is free software; you can redistribute it and/or modify it under 8 1.1 mrg the terms of the GNU General Public License as published by the Free 9 1.1 mrg Software Foundation; either version 3, or (at your option) any later 10 1.1 mrg version. 11 1.1 mrg 12 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY 13 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 1.1 mrg for more details. 16 1.1 mrg 17 1.1 mrg Under Section 7 of GPL version 3, you are granted additional 18 1.1 mrg permissions described in the GCC Runtime Library Exception, version 19 1.1 mrg 3.1, as published by the Free Software Foundation. 20 1.1 mrg 21 1.1 mrg You should have received a copy of the GNU General Public License and 22 1.1 mrg a copy of the GCC Runtime Library Exception along with this program; 23 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 24 1.1 mrg <http://www.gnu.org/licenses/>. */ 25 1.1 mrg 26 1.1 mrg /* AMD GCN does not support dynamic creation of threads. There may be many 27 1.1 mrg hardware threads, but they're all created simultaneously at launch time. 28 1.1 mrg 29 1.1 mrg This implementation is intended to provide mutexes for libgfortran, etc. 30 1.1 mrg It is not intended to provide a TLS implementation at this time, 31 1.1 mrg although that may be added later if needed. 32 1.1 mrg 33 1.1 mrg __gthread_active_p returns "1" to ensure that mutexes are used, and that 34 1.1 mrg programs attempting to use emutls will fail with the appropriate abort. 35 1.1 mrg It is expected that the TLS tests will fail. */ 36 1.1 mrg 37 1.1 mrg #ifndef GCC_GTHR_GCN_H 38 1.1 mrg #define GCC_GTHR_GCN_H 39 1.1 mrg 40 1.1 mrg #define __GTHREADS 1 41 1.1 mrg 42 1.1 mrg #ifdef __cplusplus 43 1.1 mrg extern "C" { 44 1.1 mrg #endif 45 1.1 mrg 46 1.1 mrg #ifdef _LIBOBJC 47 1.1 mrg #error "Objective C is not supported on AMD GCN" 48 1.1 mrg #else 49 1.1 mrg 50 1.1 mrg static inline int 51 1.1 mrg __gthread_active_p (void) 52 1.1 mrg { 53 1.1 mrg return 1; 54 1.1 mrg } 55 1.1 mrg 56 1.1 mrg typedef int __gthread_key_t; 57 1.1 mrg typedef int __gthread_once_t; 58 1.1 mrg typedef int __gthread_mutex_t; 59 1.1 mrg typedef int __gthread_recursive_mutex_t; 60 1.1 mrg 61 1.1 mrg #define __GTHREAD_ONCE_INIT 0 62 1.1 mrg #define __GTHREAD_MUTEX_INIT 0 63 1.1 mrg #define __GTHREAD_RECURSIVE_MUTEX_INIT 0 64 1.1 mrg 65 1.1 mrg static inline int 66 1.1 mrg __gthread_once (__gthread_once_t *__once __attribute__((unused)), 67 1.1 mrg void (*__func) (void) __attribute__((unused))) 68 1.1 mrg { 69 1.1 mrg return 0; 70 1.1 mrg } 71 1.1 mrg 72 1.1 mrg static inline int 73 1.1 mrg __gthread_key_create (__gthread_key_t *__key __attribute__((unused)), 74 1.1 mrg void (*__dtor) (void *) __attribute__((unused))) 75 1.1 mrg { 76 1.1 mrg /* Operation is not supported. */ 77 1.1 mrg return -1; 78 1.1 mrg } 79 1.1 mrg 80 1.1 mrg static inline int 81 1.1 mrg __gthread_key_delete (__gthread_key_t __key __attribute__ ((__unused__))) 82 1.1 mrg { 83 1.1 mrg /* Operation is not supported. */ 84 1.1 mrg return -1; 85 1.1 mrg } 86 1.1 mrg 87 1.1 mrg static inline void * 88 1.1 mrg __gthread_getspecific (__gthread_key_t __key __attribute__((unused))) 89 1.1 mrg { 90 1.1.1.3 mrg return 0; 91 1.1 mrg } 92 1.1 mrg 93 1.1 mrg static inline int 94 1.1 mrg __gthread_setspecific (__gthread_key_t __key __attribute__((unused)), 95 1.1 mrg const void *__ptr __attribute__((unused))) 96 1.1 mrg { 97 1.1 mrg /* Operation is not supported. */ 98 1.1 mrg return -1; 99 1.1 mrg } 100 1.1 mrg 101 1.1 mrg static inline int 102 1.1 mrg __gthread_mutex_destroy (__gthread_mutex_t *__mutex __attribute__((unused))) 103 1.1 mrg { 104 1.1 mrg return 0; 105 1.1 mrg } 106 1.1 mrg 107 1.1 mrg static inline int 108 1.1 mrg __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) 109 1.1 mrg { 110 1.1 mrg return 0; 111 1.1 mrg } 112 1.1 mrg 113 1.1 mrg 114 1.1 mrg static inline int 115 1.1 mrg __gthread_mutex_lock (__gthread_mutex_t *__mutex) 116 1.1 mrg { 117 1.1 mrg while (__sync_lock_test_and_set (__mutex, 1)) 118 1.1 mrg asm volatile ("s_sleep\t1" ::: "memory"); 119 1.1 mrg 120 1.1 mrg return 0; 121 1.1 mrg } 122 1.1 mrg 123 1.1 mrg static inline int 124 1.1 mrg __gthread_mutex_trylock (__gthread_mutex_t *__mutex) 125 1.1 mrg { 126 1.1 mrg return __sync_lock_test_and_set (__mutex, 1); 127 1.1 mrg } 128 1.1 mrg 129 1.1 mrg static inline int 130 1.1 mrg __gthread_mutex_unlock (__gthread_mutex_t *__mutex) 131 1.1 mrg { 132 1.1 mrg __sync_lock_release (__mutex); 133 1.1 mrg 134 1.1 mrg return 0; 135 1.1 mrg } 136 1.1 mrg 137 1.1 mrg static inline int 138 1.1 mrg __gthread_recursive_mutex_lock (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) 139 1.1 mrg { 140 1.1 mrg /* Operation is not supported. */ 141 1.1 mrg return -1; 142 1.1 mrg } 143 1.1 mrg 144 1.1 mrg static inline int 145 1.1 mrg __gthread_recursive_mutex_trylock (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) 146 1.1 mrg { 147 1.1 mrg /* Operation is not supported. */ 148 1.1 mrg return -1; 149 1.1 mrg } 150 1.1 mrg 151 1.1 mrg static inline int 152 1.1 mrg __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex __attribute__((unused))) 153 1.1 mrg { 154 1.1 mrg /* Operation is not supported. */ 155 1.1 mrg return -1; 156 1.1 mrg } 157 1.1 mrg #endif /* _LIBOBJC */ 158 1.1 mrg 159 1.1 mrg #ifdef __cplusplus 160 1.1 mrg } 161 1.1 mrg #endif 162 1.1 mrg 163 1.1 mrg #endif /* ! GCC_GTHR_GCN_H */ 164