From f27db333052aa24a0aad135c09ce7969bf31bc56 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Sun, 19 May 2019 09:50:19 +0000 Subject: worker/types/worker: make ID allocation atomic Message IDs are allocated for both messages from UI to workers and the other way around. Hence, the global nextId variable is accessed from multiple goroutines. Instead, use atomic to access the global counter. --- worker/types/messages.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'worker/types/messages.go') diff --git a/worker/types/messages.go b/worker/types/messages.go index 0cb6eeb..eb54a15 100644 --- a/worker/types/messages.go +++ b/worker/types/messages.go @@ -12,13 +12,13 @@ import ( type WorkerMessage interface { InResponseTo() WorkerMessage - getId() int - setId(id int) + getId() int64 + setId(id int64) } type Message struct { inResponseTo WorkerMessage - id int + id int64 } func RespondTo(msg WorkerMessage) Message { @@ -31,11 +31,11 @@ func (m Message) InResponseTo() WorkerMessage { return m.inResponseTo } -func (m Message) getId() int { +func (m Message) getId() int64 { return m.id } -func (m Message) setId(id int) { +func (m Message) setId(id int64) { m.id = id } -- cgit v1.2.3