Skip to content

Commit b538359

Browse files
author
Gusted
authored
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
1 parent af09136 commit b538359

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

modules/queue/workerpool.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ import (
2222
// they use to detect if there is a block and will grow and shrink in
2323
// response to demand as per configuration.
2424
type WorkerPool struct {
25+
// This field requires to be the first one in the struct.
26+
// This is to allow 64 bit atomic operations on 32-bit machines.
27+
// See: https://pkg.go.dev/sync/atomic#pkg-note-BUG & Gitea issue 19518
28+
numInQueue int64
2529
lock sync.Mutex
2630
baseCtx context.Context
2731
baseCtxCancel context.CancelFunc
@@ -38,7 +42,6 @@ type WorkerPool struct {
3842
blockTimeout time.Duration
3943
boostTimeout time.Duration
4044
boostWorkers int
41-
numInQueue int64
4245
}
4346

4447
var (

0 commit comments

Comments
 (0)