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/lifecycle.go | |
parent | 09c9c224ad987c12fcf8b12b52c1bec17a49b58f (diff) | |
parent | 906eb6295d54a05663a223f1dc379a16148de2d1 (diff) |
Merge release-20200211.0-33-g906eb62 (automated)
Diffstat (limited to 'pkg/sentry/mm/lifecycle.go')
-rw-r--r-- | pkg/sentry/mm/lifecycle.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/sentry/mm/lifecycle.go b/pkg/sentry/mm/lifecycle.go index 47b8fbf43..3c263ebaa 100644 --- a/pkg/sentry/mm/lifecycle.go +++ b/pkg/sentry/mm/lifecycle.go @@ -18,7 +18,6 @@ import ( "fmt" "sync/atomic" - "gvisor.dev/gvisor/pkg/atomicbitops" "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/sentry/arch" "gvisor.dev/gvisor/pkg/sentry/limits" @@ -229,7 +228,15 @@ func (mm *MemoryManager) Fork(ctx context.Context) (*MemoryManager, error) { // IncUsers increments mm's user count and returns true. If the user count is // already 0, IncUsers does nothing and returns false. func (mm *MemoryManager) IncUsers() bool { - return atomicbitops.IncUnlessZeroInt32(&mm.users) + for { + users := atomic.LoadInt32(&mm.users) + if users == 0 { + return false + } + if atomic.CompareAndSwapInt32(&mm.users, users, users+1) { + return true + } + } } // DecUsers decrements mm's user count. If the user count reaches 0, all |