diff options
author | Jamie Liu <jamieliu@google.com> | 2019-01-09 17:53:31 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-01-09 17:54:40 -0800 |
commit | 9270d940eb1a6e31587c34f4644189f3b2c002e1 (patch) | |
tree | 64bfac5c7bfa0281891ff76d7865da39ce6e3fc2 /pkg/sentry/kernel | |
parent | 6e91a98f6ba02857e381c0f199c1494c6f1d7839 (diff) |
Minor memevent fixes.
- Call MemoryEvents.done.Add(1) outside of MemoryEvents.run() so that if
MemoryEvents.Stop() => MemoryEvents.done.Wait() is called before the
goroutine starts running, it still waits for the goroutine to stop.
- Use defer to call MemoryEvents.done.Done() in MemoryEvents.run() so that it's
called even if the goroutine panics.
PiperOrigin-RevId: 228623307
Change-Id: I1b0459e7999606c1a1a271b16092b1ca87005015
Diffstat (limited to 'pkg/sentry/kernel')
-rw-r--r-- | pkg/sentry/kernel/memevent/memory_events.go | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/pkg/sentry/kernel/memevent/memory_events.go b/pkg/sentry/kernel/memevent/memory_events.go index 1a8e86827..b6283c5d1 100644 --- a/pkg/sentry/kernel/memevent/memory_events.go +++ b/pkg/sentry/kernel/memevent/memory_events.go @@ -69,11 +69,12 @@ func (m *MemoryEvents) Start() { if m.period == 0 { return } + m.done.Add(1) go m.run() // S/R-SAFE: doesn't interact with saved state. } func (m *MemoryEvents) run() { - m.done.Add(1) + defer m.done.Done() // Emit the first event immediately on startup. totalTicks.Increment() @@ -85,7 +86,6 @@ func (m *MemoryEvents) run() { for { select { case <-m.stop: - m.done.Done() return case <-ticker.C: totalTicks.Increment() |