Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Spinlock.h
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 
25 #ifndef SPINLOCK_H
26 #define SPINLOCK_H
27 
28 #ifdef __cplusplus
29  extern "C"
30  {
31 #endif
32 
55 #define i686_ARCH
56 
63 typedef volatile unsigned int MALP_Spinlock;
64 
65 #if defined(i686_ARCH) || defined(x86_64_ARCH)
66 static __inline__ int tracelib_test_and_set(MALP_Spinlock * atomic)
67 {
68  int ret;
69  __asm__ __volatile__("lock; xchgl %0, %1": "=r"(ret), "=m"(*atomic): "0"(1), "m"(*atomic):"memory");
70  return ret;
71 }
72 static __inline__ void cpu_relax(void)
73 {
74  __asm__ __volatile__("rep;nop":::"memory");
75 }
76 #elif defined(ia64_ARCH)
77 static __inline__ int tracelib_test_and_set(MALP_Spinlock * atomic)
78 {
79  int ret;
80  __asm__ __volatile__("xchg4 %0=%1, %2": "=r"(ret), "=m"(*atomic): "0"(1), "m"(*atomic):"memory");
81  return ret;
82 }
83 static __inline__ void cpu_relax(void)
84 {
85  __asm__ __volatile__("hint @pause":::"memory");
86 }
87 #elif defined(sparc_ARCH)
88 static __inline__ int tracelib_test_and_set(MALP_Spinlock * atomic)
89 {
90  char ret = 0;
91  __asm__ __volatile__("ldstub [%0], %1": "=r"(spinlock), "=r"(ret): "0"(spinlock), "1"(ret):"memory");
92  return (unsigned) ret;
93 }
94 static __inline__ void cpu_relax(void)
95 {
96  sched_yield();
97 }
98 #endif
99 
105 int MALP_Spinlock_lock(MALP_Spinlock * atomic);
106 
112 int MALP_Spinlock_unlock(MALP_Spinlock * atomic);
113 
119 int MALP_Spinlock_trylock(MALP_Spinlock * mutex);
120 
121 #ifdef __cplusplus
122  }
123 #endif
124 
125 #endif /* SPINLOCK_H */
126 
int MALP_Spinlock_unlock(MALP_Spinlock *atomic)
Unlocks the given MALP_Spinlock.
Definition: Spinlock.c:41
int MALP_Spinlock_lock(MALP_Spinlock *atomic)
Locks the given MALP_Spinlock.
Definition: Spinlock.c:29
volatile unsigned int MALP_Spinlock
The type of spinlocks in MALP.
Definition: Spinlock.h:63
int MALP_Spinlock_trylock(MALP_Spinlock *mutex)
Tries to lock the given MALP_Spinlock.
Definition: Spinlock.c:22