3 #ifndef OSL_LIGHT_MUTEX_H 4 #define OSL_LIGHT_MUTEX_H 8 # include "osl/misc/perfmon.h" 17 #if defined OSL_USE_RACE_DETECTOR || defined _MSC_VER 18 typedef std::mutex LightMutex;
19 typedef std::mutex LightMutexChar;
21 template <
class Mutex>
33 if(!m.waitLock(100))
break;
34 if(m.tryLock())
return;
37 std::this_thread::yield();
52 LightMutex(
const LightMutex&) =
delete;
53 LightMutex&
operator=(
const LightMutex&) =
delete;
61 if(data!=0)
return false;
64 asm __volatile__(
" movl $1,%0" "\n\t" 65 " xchgl (%1),%0" "\n\t" 70 # error "not supported" 75 for(
int i=0;i<counter;i++){
77 asm __volatile__(
" pause" "\n\t");
87 if(!waitLock(100))
break;
90 std::this_thread::yield();
121 class LightMutexChar {
122 LightMutexChar(
const LightMutexChar&) =
delete;
123 LightMutexChar&
operator=(
const LightMutexChar&) =
delete;
130 if(data!=0)
return false;
133 asm __volatile__(
" movb $1,%0" "\n\t" 134 " xchgb (%1),%0" "\n\t" 139 # error "not supported" 144 for(
int i=0;i<counter;i++){
146 asm __volatile__(
" pause" "\n\t");
155 for(
int i=0;i<2;i++){
156 if(!waitLock(100))
break;
157 if(tryLock())
return;
159 std::this_thread::yield();
169 # define SCOPED_LOCK(lock,m) \ 170 static osl::misc::CounterPair c(__FILE__, __FUNCTION__, __LINE__); \ 171 osl::misc::LightMutex::scoped_lock lock(c,m); 172 # define SCOPED_LOCK_CHAR(lock,m) \ 173 static osl::misc::CounterPair c(__FILE__, __FUNCTION__, __LINE__); \ 174 osl::misc::LightMutexChar::scoped_lock lock(c,m); 176 # define SCOPED_LOCK(lock,m) \ 177 osl::misc::LightMutex::scoped_lock lock(m); 178 # define SCOPED_LOCK_CHAR(lock,m) \ 179 osl::misc::LightMutexChar::scoped_lock lock(m); 182 using misc::LightMutex;
LightScopedLock(Mutex &m)
requirement: thread local
LightScopedLock(const LightScopedLock &)=delete
LightScopedLock< LightMutex > scoped_lock
LightScopedLock< LightMutexChar > scoped_lock
bool waitLock(int counter)
bool waitLock(int counter)
LightScopedLock & operator=(const LightScopedLock &)=delete
unlockable_lock(LightMutex &m)