Frames

Untitled

0
1
2
3
4
1package sabotage
2
3import (
4 "sync"
5 "sync/atomic"
6 "unsafe"
7)
8
9type mutexSpy struct {
10 state int32
11 sema uint32
12}
13
14// IsMutexLocked will return true if sync.Mutex is locked.
15func IsMutexLocked(m *sync.Mutex) bool {
16 spy := (*mutexSpy)(unsafe.Pointer(m))
17 return atomic.LoadInt32(&spy.state) == 1
18}
19
20// UnlockMutex will unlock a mutex.
21func UnlockMutex(mutex *sync.Mutex) {
22 spy := (*mutexSpy)(unsafe.Pointer(mutex))
23 atomic.StoreInt32(&spy.state, 0)
24}
25