PAPI  5.0.1.0
darwin-lock.h
Go to the documentation of this file.
00001 #ifndef _DARWIN_LOCK_H
00002 #define _DARWIN_LOCK_H
00003 
00004 #include "mb.h"
00005 
00006 /* Locking functions */
00007 
00008 #if defined(USE_PTHREAD_MUTEXES)
00009 
00010 #include <pthread.h>
00011 
00012 extern pthread_mutex_t _papi_hwd_lock_data[PAPI_MAX_LOCK];
00013 
00014 #define  _papi_hwd_lock(lck)                       \
00015 do                                                 \
00016 {                                                  \
00017    pthread_mutex_lock (&_papi_hwd_lock_data[lck]); \
00018 } while(0)
00019 #define  _papi_hwd_unlock(lck)                     \
00020 do                                                 \
00021 {                                                  \
00022   pthread_mutex_unlock(&_papi_hwd_lock_data[lck]); \
00023 } while(0)
00024 
00025 
00026 #else
00027 
00028 extern volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK];
00029 #define MUTEX_OPEN 0
00030 #define MUTEX_CLOSED 1
00031 
00032 #define  _papi_hwd_lock(lck)                    \
00033 do                                              \
00034 {                                               \
00035    unsigned int res = 0;                        \
00036    do {                                         \
00037       __asm__ __volatile__ ("lock ; " "cmpxchg %1,%2" : "=a"(res) : "q"(MUTEX_CLOSED), "m"(_papi_hwd_lock_data[lck]), "0"(MUTEX_OPEN) : "memory");  \
00038    } while(res != (unsigned int)MUTEX_OPEN);   \
00039 } while(0)
00040 #define  _papi_hwd_unlock(lck)                  \
00041 do                                              \
00042 {                                               \
00043    unsigned int res = 0;                       \
00044    __asm__ __volatile__ ("xchg %0,%1" : "=r"(res) : "m"(_papi_hwd_lock_data[lck]), "0"(MUTEX_OPEN) : "memory");                                \
00045 } while(0)
00046 
00047 #endif 
00048 #endif
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines