1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-17 16:12:42 +08:00

spin locker

This commit is contained in:
2022-06-07 10:57:42 +08:00
parent f36b4fabd6
commit 4e97d13d20

View File

@ -11,6 +11,10 @@ func NewSpinLocker() *spinLock {
return new(spinLock)
}
func (sl *spinLock) TryLock() bool {
return atomic.CompareAndSwapUint32((*uint32)(sl), 0, 1)
}
func (sl *spinLock) Lock() {
for !atomic.CompareAndSwapUint32((*uint32)(sl), 0, 1) {
runtime.Gosched()