github.com/cyub/threadlocal@v0.0.0-20220816024249-5db4997a97f4/mutex.go (about) 1 package threadlocal 2 3 import ( 4 _ "unsafe" 5 ) 6 7 // Mutual exclusion locks. In the uncontended case, 8 // as fast as spin locks (just a few user-level instructions), 9 // but on the contention path they sleep in the kernel. 10 // A zeroed Mutex is unlocked (no need to initialize each lock). 11 type mutex struct { 12 // Futex-based impl treats it as uint32 key, 13 // while sema-based impl as M* waitm. 14 // Used to be a union, but unions break precise GC. 15 key uintptr 16 } 17 18 //go:linkname lock runtime.lock 19 func lock(l *mutex) 20 21 //go:linkname unlock runtime.unlock 22 func unlock(l *mutex)