-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1075 from McStork/libbeat-proper-shut
Ensure proper shutdown of libbeat
- Loading branch information
Showing
24 changed files
with
302 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package common | ||
|
||
import ( | ||
"sync" | ||
) | ||
|
||
// WorkerSignal ensure all events have been | ||
// treated before closing Go routines | ||
type WorkerSignal struct { | ||
Done chan struct{} | ||
wgEvent sync.WaitGroup | ||
wgWorker sync.WaitGroup | ||
} | ||
|
||
func NewWorkerSignal() *WorkerSignal { | ||
w := &WorkerSignal{} | ||
w.Init() | ||
return w | ||
} | ||
|
||
func (ws *WorkerSignal) Init() { | ||
ws.Done = make(chan struct{}) | ||
} | ||
|
||
func (ws *WorkerSignal) AddEvent(delta int) { | ||
ws.wgEvent.Add(delta) | ||
} | ||
|
||
func (ws *WorkerSignal) DoneEvent() { | ||
ws.wgEvent.Done() | ||
} | ||
|
||
func (ws *WorkerSignal) WorkerStart() { | ||
ws.wgWorker.Add(1) | ||
} | ||
|
||
func (ws *WorkerSignal) WorkerFinished() { | ||
ws.wgWorker.Done() | ||
} | ||
|
||
func (ws *WorkerSignal) Stop() { | ||
ws.wgEvent.Wait() // Wait for all events to be dealt with | ||
close(ws.Done) // Ask Go routines to exit | ||
ws.wgWorker.Wait() // Wait for Go routines to finish | ||
} |
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
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.