12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package reedsolomon
- import (
- "runtime"
- "github.com/klauspost/cpuid"
- )
- 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
- }
-
- defaultOptions.useSSSE3 = cpuid.CPU.SSSE3()
- defaultOptions.useAVX2 = cpuid.CPU.AVX2()
- }
- func WithMaxGoroutines(n int) Option {
- return func(o *options) {
- if n > 0 {
- o.maxGoroutines = n
- }
- }
- }
- func WithMinSplitSize(n int) Option {
- return func(o *options) {
- if n > 0 {
- o.minSplitSize = 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
- }
- }
|