config/linux/mips/futex.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005, 2008, 2009 Free Software Foundation, Inc.
00002    Contributed by Ilie Garbacea <ilie@mips.com>, Chao-ying Fu <fu@mips.com>.
00003 
00004    This file is part of the GNU OpenMP Library (libgomp).
00005 
00006    Libgomp is free software; you can redistribute it and/or modify it
00007    under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 3, or (at your option)
00009    any later version.
00010 
00011    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
00012    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00014    more details.
00015 
00016    Under Section 7 of GPL version 3, you are granted additional
00017    permissions described in the GCC Runtime Library Exception, version
00018    3.1, as published by the Free Software Foundation.
00019 
00020    You should have received a copy of the GNU General Public License and
00021    a copy of the GCC Runtime Library Exception along with this program;
00022    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023    <http://www.gnu.org/licenses/>.  */
00024 
00025 /* Provide target-specific access to the futex system call.  */
00026 
00027 #include <sys/syscall.h>
00028 #define FUTEX_WAIT 0
00029 #define FUTEX_WAKE 1
00030 
00031 static inline void
00032 sys_futex0 (int *addr, int op, int val)
00033 {
00034   register unsigned long __v0 asm("$2") = (unsigned long) SYS_futex;
00035   register unsigned long __a0 asm("$4") = (unsigned long) addr;
00036   register unsigned long __a1 asm("$5") = (unsigned long) op;
00037   register unsigned long __a2 asm("$6") = (unsigned long) val;
00038   register unsigned long __a3 asm("$7") = 0;
00039 
00040   __asm volatile ("syscall"
00041           /* returns $a3 (errno), $v0 (return value) */
00042           : "=r" (__v0), "=r" (__a3)
00043           /* arguments in v0 (syscall) a0-a3 */
00044           : "r" (__v0), "r" (__a0), "r" (__a1), "r" (__a2), "r" (__a3)
00045           /* clobbers at, v1, t0-t9, memory */
00046           : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", "$14",
00047             "$15", "$24", "$25", "memory");
00048 }
00049 
00050 static inline void
00051 futex_wait (int *addr, int val)
00052 {
00053   sys_futex0 (addr, FUTEX_WAIT, val);
00054 }
00055 
00056 static inline void
00057 futex_wake (int *addr, int count)
00058 {
00059   sys_futex0 (addr, FUTEX_WAKE, count);
00060 }
00061 
00062 static inline void
00063 cpu_relax (void)
00064 {
00065   __asm volatile ("" : : : "memory");
00066 }
00067 
00068 static inline void
00069 atomic_write_barrier (void)
00070 {
00071   __sync_synchronize ();
00072 }

Generated on Fri Apr 5 05:38:09 2013 for Libgomp by  doxygen 1.4.7