Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added -num-threads option #4

Merged
merged 1 commit into from
Feb 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ import (
"github.com/zmap/zlint/zlint/ringbuff"
)

const CHUNKSIZE int = 10000 //number of certs per work unit, must be >=1
const THREADS int = 4 //number of processing threads for --threads mode, must be >=1
const CHUNKSIZE int = 10000 //number of certs per work unit, must be >=1
const DEFAULT_THREADS uint = 4 //default number of processing threads for -threads mode, must be >=1

var ( //flags
inPath string
outPath string
outStat string
multi bool
threaded bool
inPath string
outPath string
outStat string
multi bool
threaded bool
numThreads uint
)

var ( //sync values for --threads
var ( //sync values for -threads
inBuffer ringbuff.RingBuffer
outBuffer ringbuff.RingBuffer
poisonBarrier sync.WaitGroup //used prevent outBuffer from being poisoned before Enqueueing is complete
Expand All @@ -44,7 +45,8 @@ func init() {
flag.StringVar(&outPath, "out-file", "-", "File path for the output JSON.")
flag.StringVar(&outStat, "out-stat", "-", "File path for the output stats.")
flag.BoolVar(&multi, "multi", false, "Use this flag to specify inserting many certs at once. Certs in this mode must be Base64 encoded DER strings, one per line.")
flag.BoolVar(&threaded, "threads", false, "Use this flag to specify that --multi mode runs multi-threaded. This has no effect otherwise.")
flag.BoolVar(&threaded, "threads", false, "Use this flag to specify that -multi mode runs multi-threaded. This has no effect otherwise.")
flag.UintVar(&numThreads, "num-threads", DEFAULT_THREADS, "Use this flag to specify the number of threads in -threads mode. This has no effect otherwise.")
flag.Parse()
}

Expand Down Expand Up @@ -170,13 +172,13 @@ func threadMode() {
inBuffer.Init(30)
outBuffer.Init(40)
mainWait = sync.NewCond(&exittex)
poisonBarrier.Add(1 + THREADS) //requires all processing threads AND the reader to Done()
poisonBarrier.Add(1 + int(numThreads)) //requires all processing threads AND the reader to Done()

//initiate reader
go readChunks()

//initiate processing
for i := 1; i <= THREADS; i++ {
for i := 1; i <= int(numThreads); i++ {
go processChunks()
}

Expand Down