diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-02-18 21:46:04 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-02-18 21:46:04 +0000 |
commit | 212b10c3606d3255a445a81834192e390db7f549 (patch) | |
tree | fec1fc6e6bc06d696d99f6203ce5a2addbff5969 /pkg/sentry/mm/address_space.go | |
parent | 09c9c224ad987c12fcf8b12b52c1bec17a49b58f (diff) | |
parent | 906eb6295d54a05663a223f1dc379a16148de2d1 (diff) |
Merge release-20200211.0-33-g906eb62 (automated)
Diffstat (limited to 'pkg/sentry/mm/address_space.go')
-rw-r--r-- | pkg/sentry/mm/address_space.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/pkg/sentry/mm/address_space.go b/pkg/sentry/mm/address_space.go index e58a63deb..94d39af60 100644 --- a/pkg/sentry/mm/address_space.go +++ b/pkg/sentry/mm/address_space.go @@ -18,7 +18,6 @@ import ( "fmt" "sync/atomic" - "gvisor.dev/gvisor/pkg/atomicbitops" "gvisor.dev/gvisor/pkg/sentry/platform" "gvisor.dev/gvisor/pkg/usermem" ) @@ -42,8 +41,15 @@ func (mm *MemoryManager) AddressSpace() platform.AddressSpace { func (mm *MemoryManager) Activate() error { // Fast path: the MemoryManager already has an active // platform.AddressSpace, and we just need to indicate that we need it too. - if atomicbitops.IncUnlessZeroInt32(&mm.active) { - return nil + for { + active := atomic.LoadInt32(&mm.active) + if active == 0 { + // Fall back to the slow path. + break + } + if atomic.CompareAndSwapInt32(&mm.active, active, active+1) { + return nil + } } for { @@ -118,8 +124,15 @@ func (mm *MemoryManager) Activate() error { func (mm *MemoryManager) Deactivate() { // Fast path: this is not the last goroutine to deactivate the // MemoryManager. - if atomicbitops.DecUnlessOneInt32(&mm.active) { - return + for { + active := atomic.LoadInt32(&mm.active) + if active == 1 { + // Fall back to the slow path. + break + } + if atomic.CompareAndSwapInt32(&mm.active, active, active-1) { + return + } } mm.activeMu.Lock() |