summaryrefslogtreecommitdiff
path: root/worker_watcher.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-15 11:46:23 +0300
committerValery Piashchynski <[email protected]>2020-12-15 11:46:23 +0300
commit0652f9f507f3b7a09d0b7f259588c794bd20bc02 (patch)
tree1fb8db5006e0dece7b9e23a2d28615d533c0fb4e /worker_watcher.go
parent9b1c2648bdbf80bdf43fbe2c64d06cfbad1340fc (diff)
Tests fixed
Diffstat (limited to 'worker_watcher.go')
-rwxr-xr-xworker_watcher.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/worker_watcher.go b/worker_watcher.go
index fa160d57..f9b3d372 100755
--- a/worker_watcher.go
+++ b/worker_watcher.go
@@ -32,6 +32,8 @@ func (stack *Stack) Reset() {
stack.workers = nil
}
+// Push worker back to the stack
+// If stack in destroy state, Push will provide 100ms window to unlock the mutex
func (stack *Stack) Push(w WorkerBase) {
stack.mutex.Lock()
defer stack.mutex.Unlock()
@@ -42,13 +44,13 @@ func (stack *Stack) Push(w WorkerBase) {
func (stack *Stack) IsEmpty() bool {
stack.mutex.Lock()
defer stack.mutex.Unlock()
-
return len(stack.workers) == 0
}
func (stack *Stack) Pop() (WorkerBase, bool) {
stack.mutex.Lock()
defer stack.mutex.Unlock()
+
// do not release new stack
if stack.destroy {
return nil, true
@@ -58,6 +60,7 @@ func (stack *Stack) Pop() (WorkerBase, bool) {
return nil, false
}
+ // move worker
w := stack.workers[len(stack.workers)-1]
stack.workers = stack.workers[:len(stack.workers)-1]
stack.actualNumOfWorkers--
@@ -80,6 +83,7 @@ func (stack *Stack) FindAndRemoveByPid(pid int64) bool {
return false
}
+// Workers return copy of the workers in the stack
func (stack *Stack) Workers() []WorkerBase {
stack.mutex.Lock()
defer stack.mutex.Unlock()