From b5383590de41b4311663e1d81ab5892054b6ce94 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 27 Apr 2022 15:32:04 +0000 Subject: [PATCH] Fix 64-bit atomic operations on 32-bit machines (#19531) - Doing 64-bit atomic operations on 32-bit machines is a bit tricky by golang, as they can only be done under certain set of conditions(https://pkg.go.dev/sync/atomic#pkg-note-BUG). - This PR fixes such case whereby the conditions weren't met, it moves the int64 to the first field of the struct, which will 64-bit operations happening on this property on 32-bit machines. - Resolves #19518 --- modules/queue/workerpool.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/queue/workerpool.go b/modules/queue/workerpool.go index 2d8504598a1a..bdf04a363b79 100644 --- a/modules/queue/workerpool.go +++ b/modules/queue/workerpool.go @@ -22,6 +22,10 @@ import ( // they use to detect if there is a block and will grow and shrink in // response to demand as per configuration. type WorkerPool struct { + // This field requires to be the first one in the struct. + // This is to allow 64 bit atomic operations on 32-bit machines. + // See: https://pkg.go.dev/sync/atomic#pkg-note-BUG & Gitea issue 19518 + numInQueue int64 lock sync.Mutex baseCtx context.Context baseCtxCancel context.CancelFunc @@ -38,7 +42,6 @@ type WorkerPool struct { blockTimeout time.Duration boostTimeout time.Duration boostWorkers int - numInQueue int64 } var (