PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
darwin-lock.h
Go to the documentation of this file.
1 #ifndef _DARWIN_LOCK_H
2 #define _DARWIN_LOCK_H
3 
4 #include "mb.h"
5 
6 /* Locking functions */
7 
8 #if defined(USE_PTHREAD_MUTEXES)
9 
10 #include <pthread.h>
11 
12 extern pthread_mutex_t _papi_hwd_lock_data[PAPI_MAX_LOCK];
13 
14 #define _papi_hwd_lock(lck) \
15 do \
16 { \
17  pthread_mutex_lock (&_papi_hwd_lock_data[lck]); \
18 } while(0)
19 #define _papi_hwd_unlock(lck) \
20 do \
21 { \
22  pthread_mutex_unlock(&_papi_hwd_lock_data[lck]); \
23 } while(0)
24 
25 
26 #else
27 
28 extern volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK];
29 #define MUTEX_OPEN 0
30 #define MUTEX_CLOSED 1
31 
32 #define _papi_hwd_lock(lck) \
33 do \
34 { \
35  unsigned int res = 0; \
36  do { \
37  __asm__ __volatile__ ("lock ; " "cmpxchg %1,%2" : "=a"(res) : "q"(MUTEX_CLOSED), "m"(_papi_hwd_lock_data[lck]), "0"(MUTEX_OPEN) : "memory"); \
38  } while(res != (unsigned int)MUTEX_OPEN); \
39 } while(0)
40 #define _papi_hwd_unlock(lck) \
41 do \
42 { \
43  unsigned int res = 0; \
44  __asm__ __volatile__ ("xchg %0,%1" : "=r"(res) : "m"(_papi_hwd_lock_data[lck]), "0"(MUTEX_OPEN) : "memory"); \
45 } while(0)
46 
47 #endif
48 #endif
#define PAPI_MAX_LOCK
Definition: papi_lock.h:18
volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]
Definition: darwin-common.c:32