diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-01-22 03:49:16 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-01-22 03:49:16 +0000 |
commit | 86af6e6efa1d0798757fc530c5907985369fa6fe (patch) | |
tree | a375a39778431d1ae215b08a8e37bdc5726366bb /pkg/sync | |
parent | 4450d973d9b18d7bfc9a7647cc5640440df6de70 (diff) | |
parent | 6a59e7f510a7b12f8b3bd768dfe569033ef07d30 (diff) |
Merge release-20200115.0-69-g6a59e7f (automated)
Diffstat (limited to 'pkg/sync')
-rwxr-xr-x | pkg/sync/aliases.go | 6 | ||||
-rwxr-xr-x | pkg/sync/downgradable_rwmutex_unsafe.go | 26 | ||||
-rwxr-xr-x | pkg/sync/tmutex_unsafe.go | 8 |
3 files changed, 17 insertions, 23 deletions
diff --git a/pkg/sync/aliases.go b/pkg/sync/aliases.go index 20c7ca041..d2d7132fa 100755 --- a/pkg/sync/aliases.go +++ b/pkg/sync/aliases.go @@ -11,12 +11,6 @@ import ( // Aliases of standard library types. type ( - // Mutex is an alias of sync.Mutex. - Mutex = sync.Mutex - - // RWMutex is an alias of sync.RWMutex. - RWMutex = sync.RWMutex - // Cond is an alias of sync.Cond. Cond = sync.Cond diff --git a/pkg/sync/downgradable_rwmutex_unsafe.go b/pkg/sync/downgradable_rwmutex_unsafe.go index 0d321f5e3..ea6cdc447 100755 --- a/pkg/sync/downgradable_rwmutex_unsafe.go +++ b/pkg/sync/downgradable_rwmutex_unsafe.go @@ -29,10 +29,10 @@ func runtimeSemacquire(s *uint32) //go:linkname runtimeSemrelease sync.runtime_Semrelease func runtimeSemrelease(s *uint32, handoff bool, skipframes int) -// DowngradableRWMutex is identical to sync.RWMutex, but adds the DowngradeLock, +// RWMutex is identical to sync.RWMutex, but adds the DowngradeLock, // TryLock and TryRLock methods. -type DowngradableRWMutex struct { - w TMutex // held if there are pending writers +type RWMutex struct { + w Mutex // held if there are pending writers writerSem uint32 // semaphore for writers to wait for completing readers readerSem uint32 // semaphore for readers to wait for completing writers readerCount int32 // number of pending readers @@ -43,7 +43,7 @@ const rwmutexMaxReaders = 1 << 30 // TryRLock locks rw for reading. It returns true if it succeeds and false // otherwise. It does not block. -func (rw *DowngradableRWMutex) TryRLock() bool { +func (rw *RWMutex) TryRLock() bool { if RaceEnabled { RaceDisable() } @@ -67,7 +67,7 @@ func (rw *DowngradableRWMutex) TryRLock() bool { } // RLock locks rw for reading. -func (rw *DowngradableRWMutex) RLock() { +func (rw *RWMutex) RLock() { if RaceEnabled { RaceDisable() } @@ -82,14 +82,14 @@ func (rw *DowngradableRWMutex) RLock() { } // RUnlock undoes a single RLock call. -func (rw *DowngradableRWMutex) RUnlock() { +func (rw *RWMutex) RUnlock() { if RaceEnabled { RaceReleaseMerge(unsafe.Pointer(&rw.writerSem)) RaceDisable() } if r := atomic.AddInt32(&rw.readerCount, -1); r < 0 { if r+1 == 0 || r+1 == -rwmutexMaxReaders { - panic("RUnlock of unlocked DowngradableRWMutex") + panic("RUnlock of unlocked RWMutex") } // A writer is pending. if atomic.AddInt32(&rw.readerWait, -1) == 0 { @@ -104,7 +104,7 @@ func (rw *DowngradableRWMutex) RUnlock() { // TryLock locks rw for writing. It returns true if it succeeds and false // otherwise. It does not block. -func (rw *DowngradableRWMutex) TryLock() bool { +func (rw *RWMutex) TryLock() bool { if RaceEnabled { RaceDisable() } @@ -131,7 +131,7 @@ func (rw *DowngradableRWMutex) TryLock() bool { } // Lock locks rw for writing. -func (rw *DowngradableRWMutex) Lock() { +func (rw *RWMutex) Lock() { if RaceEnabled { RaceDisable() } @@ -150,7 +150,7 @@ func (rw *DowngradableRWMutex) Lock() { } // Unlock unlocks rw for writing. -func (rw *DowngradableRWMutex) Unlock() { +func (rw *RWMutex) Unlock() { if RaceEnabled { RaceRelease(unsafe.Pointer(&rw.writerSem)) RaceRelease(unsafe.Pointer(&rw.readerSem)) @@ -159,7 +159,7 @@ func (rw *DowngradableRWMutex) Unlock() { // Announce to readers there is no active writer. r := atomic.AddInt32(&rw.readerCount, rwmutexMaxReaders) if r >= rwmutexMaxReaders { - panic("Unlock of unlocked DowngradableRWMutex") + panic("Unlock of unlocked RWMutex") } // Unblock blocked readers, if any. for i := 0; i < int(r); i++ { @@ -173,7 +173,7 @@ func (rw *DowngradableRWMutex) Unlock() { } // DowngradeLock atomically unlocks rw for writing and locks it for reading. -func (rw *DowngradableRWMutex) DowngradeLock() { +func (rw *RWMutex) DowngradeLock() { if RaceEnabled { RaceRelease(unsafe.Pointer(&rw.readerSem)) RaceDisable() @@ -181,7 +181,7 @@ func (rw *DowngradableRWMutex) DowngradeLock() { // Announce to readers there is no active writer and one additional reader. r := atomic.AddInt32(&rw.readerCount, rwmutexMaxReaders+1) if r >= rwmutexMaxReaders+1 { - panic("DowngradeLock of unlocked DowngradableRWMutex") + panic("DowngradeLock of unlocked RWMutex") } // Unblock blocked readers, if any. Note that this loop starts as 1 since r // includes this goroutine. diff --git a/pkg/sync/tmutex_unsafe.go b/pkg/sync/tmutex_unsafe.go index 3c32f8371..3dd15578b 100755 --- a/pkg/sync/tmutex_unsafe.go +++ b/pkg/sync/tmutex_unsafe.go @@ -17,8 +17,8 @@ import ( "unsafe" ) -// TMutex is a try lock. -type TMutex struct { +// Mutex is a try lock. +type Mutex struct { sync.Mutex } @@ -27,7 +27,7 @@ type syncMutex struct { sema uint32 } -func (m *TMutex) state() *int32 { +func (m *Mutex) state() *int32 { return &(*syncMutex)(unsafe.Pointer(&m.Mutex)).state } @@ -38,7 +38,7 @@ const ( // TryLock tries to aquire the mutex. It returns true if it succeeds and false // otherwise. TryLock does not block. -func (m *TMutex) TryLock() bool { +func (m *Mutex) TryLock() bool { if atomic.CompareAndSwapInt32(m.state(), mutexUnlocked, mutexLocked) { if RaceEnabled { RaceAcquire(unsafe.Pointer(&m.Mutex)) |