1 /* Copyright (C) 2011-2013 Free Software Foundation, Inc. 2 Contributed by Walter Lee (walt@tilera.com) 3 4 This file is part of the GNU OpenMP Library (libgomp). 5 6 Libgomp is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3, or (at your option) 9 any later version. 10 11 Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY 12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 more details. 15 16 Under Section 7 of GPL version 3, you are granted additional 17 permissions described in the GCC Runtime Library Exception, version 18 3.1, as published by the Free Software Foundation. 19 20 You should have received a copy of the GNU General Public License and 21 a copy of the GCC Runtime Library Exception along with this program; 22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23 <http://www.gnu.org/licenses/>. */ 24 25 /* Provide target-specific access to the futex system call. */ 26 27 #include <sys/syscall.h> 28 #include <linux/futex.h> 29 30 static inline void 31 sys_futex0 (int *addr, int op, int val) 32 { 33 long _sys_result; 34 long _clobber_r2, _clobber_r3, _clobber_r4, _clobber_r5, _clobber_r10; 35 int err; 36 37 __asm__ __volatile__ ( 38 "swint1" 39 : "=R00" (_sys_result), "=R01" (err), "=R02" (_clobber_r2), 40 "=R03" (_clobber_r3), "=R04" (_clobber_r4), "=R05" (_clobber_r5), 41 "=R10" (_clobber_r10) 42 : "R10" (SYS_futex), "R00" (addr), "R01" (op), "R02" (val), 43 "R03" (0) 44 : "r6", "r7", 45 "r8", "r9", "r11", "r12", "r13", "r14", "r15", 46 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 47 "r24", "r25", "r26", "r27", "r28", "r29", "memory"); 48 } 49 50 static inline void 51 futex_wait (int *addr, int val) 52 { 53 sys_futex0 (addr, FUTEX_WAIT, val); 54 } 55 56 static inline void 57 futex_wake (int *addr, int count) 58 { 59 sys_futex0 (addr, FUTEX_WAKE, count); 60 } 61 62 static inline void 63 cpu_relax (void) 64 { 65 __asm volatile ("" : : : "memory"); 66 } 67 68 static inline void 69 atomic_write_barrier (void) 70 { 71 __sync_synchronize (); 72 } 73