-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add options Make constants changeable as options. The API remains backwards compatible. * Update documentation. * Fix line endings * fmt * fmt * Use functions for parameters. Much neater.
- Loading branch information
Showing
9 changed files
with
210 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package reedsolomon | ||
|
||
import ( | ||
"runtime" | ||
|
||
"github.com/klauspost/cpuid" | ||
) | ||
|
||
// Option allows to override processing parameters. | ||
type Option func(*options) | ||
|
||
type options struct { | ||
maxGoroutines int | ||
minSplitSize int | ||
useAVX2, useSSSE3 bool | ||
} | ||
|
||
var defaultOptions = options{ | ||
maxGoroutines: 50, | ||
minSplitSize: 512, | ||
} | ||
|
||
func init() { | ||
if runtime.GOMAXPROCS(0) <= 1 { | ||
defaultOptions.maxGoroutines = 1 | ||
} | ||
// Detect CPU capabilities. | ||
defaultOptions.useSSSE3 = cpuid.CPU.SSSE3() | ||
defaultOptions.useAVX2 = cpuid.CPU.AVX2() | ||
} | ||
|
||
// WithMaxGoroutines is the maximum number of goroutines number for encoding & decoding. | ||
// Jobs will be split into this many parts, unless each goroutine would have to process | ||
// less than minSplitSize bytes (set with WithMinSplitSize). | ||
// For the best speed, keep this well above the GOMAXPROCS number for more fine grained | ||
// scheduling. | ||
// If n <= 0, it is ignored. | ||
func WithMaxGoroutines(n int) Option { | ||
return func(o *options) { | ||
if n > 0 { | ||
o.maxGoroutines = n | ||
} | ||
} | ||
} | ||
|
||
// MinSplitSize Is the minimum encoding size in bytes per goroutine. | ||
// See WithMaxGoroutines on how jobs are split. | ||
// If n <= 0, it is ignored. | ||
func WithMinSplitSize(n int) Option { | ||
return func(o *options) { | ||
if n > 0 { | ||
o.maxGoroutines = n | ||
} | ||
} | ||
} | ||
|
||
func withSSE3(enabled bool) Option { | ||
return func(o *options) { | ||
o.useSSSE3 = enabled | ||
} | ||
} | ||
|
||
func withAVX2(enabled bool) Option { | ||
return func(o *options) { | ||
o.useAVX2 = enabled | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.