Skip to content

Commit

Permalink
Ensure 64bit alignment on 32bit builds for atomics (#3065)
Browse files Browse the repository at this point in the history
Keep elements that are used with atomic.* functions as first element
of struct because it guarantees 64bit alignment on 32 bit machines.
atomic.* functions crash if operand is not aligned at 64bit.
See golang/go#599
  • Loading branch information
rkoehn authored Feb 4, 2020
1 parent ac9b942 commit 6092743
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
9 changes: 6 additions & 3 deletions cmd/parallel-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,18 @@ const (

// ParallelManager - helps manage parallel workers to run tasks
type ParallelManager struct {
// Calculate sent bytes.
// Keep this as first element of struct because it guarantees 64bit
// alignment on 32 bit machines. atomic.* functions crash if operand is not
// aligned at 64bit. See https://github.com/golang/go/issues/599
sentBytes int64

// Synchronize workers
wg *sync.WaitGroup

// Current threads number
workersNum uint32

// Calculate sent bytes.
sentBytes int64

// Channel to receive tasks to run
queueCh chan func() URLs
// Channel to send back results
Expand Down
14 changes: 10 additions & 4 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ func NewQuietStatus(hook io.Reader) Status {

// QuietStatus will only show the progress and summary
type QuietStatus struct {
*accounter
hook io.Reader
// Keep this as first element of struct because it guarantees 64bit
// alignment on 32 bit machines. atomic.* functions crash if operand is not
// aligned at 64bit. See https://github.com/golang/go/issues/599
counts int64
*accounter
hook io.Reader
}

// Read implements the io.Reader interface
Expand Down Expand Up @@ -151,9 +154,12 @@ func NewProgressStatus(hook io.Reader) Status {

// ProgressStatus shows a progressbar
type ProgressStatus struct {
*progressBar
hook io.Reader
// Keep this as first element of struct because it guarantees 64bit
// alignment on 32 bit machines. atomic.* functions crash if operand is not
// aligned at 64bit. See https://github.com/golang/go/issues/599
counts int64
*progressBar
hook io.Reader
}

// Read implements the io.Reader interface
Expand Down

0 comments on commit 6092743

Please sign in to comment.