diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-09-06 18:12:46 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2019-09-06 18:12:46 +0000 |
commit | aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13 (patch) | |
tree | 7e63b06d1eec92beec6997c9d3ab47a5d6a835be /libgo/go/sync/mutex.go | |
parent | 920ea3b8ba3164b61ac9490dfdfceb6936eda6dd (diff) | |
download | gcc-aa8901e9bb0399d2c16f988ba2fe46eb0c0c5d13.tar.gz |
libgo: update to Go 1.13beta1 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/193497
From-SVN: r275473
Diffstat (limited to 'libgo/go/sync/mutex.go')
-rw-r--r-- | libgo/go/sync/mutex.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/libgo/go/sync/mutex.go b/libgo/go/sync/mutex.go index 4c5582c8094..11ad20c9757 100644 --- a/libgo/go/sync/mutex.go +++ b/libgo/go/sync/mutex.go @@ -77,7 +77,11 @@ func (m *Mutex) Lock() { } return } + // Slow path (outlined so that the fast path can be inlined) + m.lockSlow() +} +func (m *Mutex) lockSlow() { var waitStartTime int64 starving := false awoke := false @@ -131,7 +135,7 @@ func (m *Mutex) Lock() { if waitStartTime == 0 { waitStartTime = runtime_nanotime() } - runtime_SemacquireMutex(&m.sema, queueLifo) + runtime_SemacquireMutex(&m.sema, queueLifo, 1) starving = starving || runtime_nanotime()-waitStartTime > starvationThresholdNs old = m.state if old&mutexStarving != 0 { @@ -180,6 +184,14 @@ func (m *Mutex) Unlock() { // Fast path: drop lock bit. new := atomic.AddInt32(&m.state, -mutexLocked) + if new != 0 { + // Outlined slow path to allow inlining the fast path. + // To hide unlockSlow during tracing we skip one extra frame when tracing GoUnblock. + m.unlockSlow(new) + } +} + +func (m *Mutex) unlockSlow(new int32) { if (new+mutexLocked)&mutexLocked == 0 { throw("sync: unlock of unlocked mutex") } @@ -198,7 +210,7 @@ func (m *Mutex) Unlock() { // Grab the right to wake someone. new = (old - 1<<mutexWaiterShift) | mutexWoken if atomic.CompareAndSwapInt32(&m.state, old, new) { - runtime_Semrelease(&m.sema, false) + runtime_Semrelease(&m.sema, false, 1) return } old = m.state @@ -208,6 +220,6 @@ func (m *Mutex) Unlock() { // Note: mutexLocked is not set, the waiter will set it after wakeup. // But mutex is still considered locked if mutexStarving is set, // so new coming goroutines won't acquire it. - runtime_Semrelease(&m.sema, true) + runtime_Semrelease(&m.sema, true, 1) } } |