Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Spinlock.c
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 #include "Spinlock.h"
20 
21 
23 {
24  unsigned int *p = (unsigned int *) mutex;
25  return !tracelib_test_and_set(p);
26 }
27 
28 
30 {
31  unsigned int *p = (unsigned int *) mutex;
32  while (tracelib_test_and_set(p)) {
33 
34  do {
35  cpu_relax();
36  } while (*p);
37  }
38  return 0;
39 }
40 
42 {
43  *mutex = 0;
44  return 0;
45 }
void * p
the void* (to be get by dlsym)
Definition: Posix_Wrapp.h:32
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
Definition: Spinlock.c:41
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
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