Skip to content

Commit 1465e0c

Browse files
author
Gusted
authored
Fix 64-bit atomic operations on 32-bit machines (#19531) (#19532)
- Backport #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
1 parent 928b603 commit 1465e0c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/queue/workerpool.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
// they use to detect if there is a block and will grow and shrink in
2020
// response to demand as per configuration.
2121
type WorkerPool struct {
22+
// This field requires to be the first one in the struct.
23+
// This is to allow 64 bit atomic operations on 32-bit machines.
24+
// See: https://pkg.go.dev/sync/atomic#pkg-note-BUG & Gitea issue 19518
25+
numInQueue int64
2226
lock sync.Mutex
2327
baseCtx context.Context
2428
baseCtxCancel context.CancelFunc
@@ -32,7 +36,6 @@ type WorkerPool struct {
3236
blockTimeout time.Duration
3337
boostTimeout time.Duration
3438
boostWorkers int
35-
numInQueue int64
3639
}
3740

3841
// WorkerPoolConfiguration is the basic configuration for a WorkerPool

0 commit comments

Comments
 (0)