Skip to content

Commit

Permalink
Fix 64-bit atomic operations on 32-bit machines (go-gitea#19531) (go-…
Browse files Browse the repository at this point in the history
…gitea#19532)

- Backport go-gitea#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 go-gitea#19518
  • Loading branch information
Gusted authored and fnetX committed Apr 28, 2022
1 parent 9b00d79 commit dc03d44
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/queue/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
Expand All @@ -32,7 +36,6 @@ type WorkerPool struct {
blockTimeout time.Duration
boostTimeout time.Duration
boostWorkers int
numInQueue int64
}

// WorkerPoolConfiguration is the basic configuration for a WorkerPool
Expand Down

0 comments on commit dc03d44

Please sign in to comment.