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