summaryrefslogtreecommitdiff
path: root/worker_watcher.go
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2020-12-15 10:26:45 +0300
committerValery Piashchynski <[email protected]>2020-12-15 10:26:45 +0300
commitcd5a6098b7d671c0fa980f0923f8d6d3733faf68 (patch)
tree4dcb4956d1839c347a5f9e5f4590969ad47861f0 /worker_watcher.go
parent3cf93d96d24201758fb5c23529af90050c3914cb (diff)
Update worker_watcher, psr-worker for gzip moved to the tests
Diffstat (limited to 'worker_watcher.go')
-rwxr-xr-xworker_watcher.go32
1 files changed, 21 insertions, 11 deletions
diff --git a/worker_watcher.go b/worker_watcher.go
index 3afb91ca..fa160d57 100755
--- a/worker_watcher.go
+++ b/worker_watcher.go
@@ -80,6 +80,25 @@ func (stack *Stack) FindAndRemoveByPid(pid int64) bool {
return false
}
+func (stack *Stack) Workers() []WorkerBase {
+ stack.mutex.Lock()
+ defer stack.mutex.Unlock()
+ workersCopy := make([]WorkerBase, 0, 1)
+ // copy
+ for _, v := range stack.workers {
+ sw := v.(SyncWorker)
+ workersCopy = append(workersCopy, sw)
+ }
+
+ return workersCopy
+}
+
+func (stack *Stack) isDestroying() bool {
+ stack.mutex.Lock()
+ defer stack.mutex.Unlock()
+ return stack.destroy
+}
+
// we also have to give a chance to pool to Push worker (return it)
func (stack *Stack) Destroy(ctx context.Context) {
stack.mutex.Lock()
@@ -260,7 +279,6 @@ func (ww *workerWatcher) RemoveWorker(wb WorkerBase) error {
// O(1) operation
func (ww *workerWatcher) PushWorker(w WorkerBase) {
- //ww.IncreaseWorkersCount()
ww.mutex.Lock()
defer ww.mutex.Unlock()
ww.stack.Push(w)
@@ -268,21 +286,13 @@ func (ww *workerWatcher) PushWorker(w WorkerBase) {
// Destroy all underlying stack (but let them to complete the task)
func (ww *workerWatcher) Destroy(ctx context.Context) {
- // destroy stack
+ // destroy stack, we don't use ww mutex here, since we should be able to push worker
ww.stack.Destroy(ctx)
}
// Warning, this is O(n) operation, and it will return copy of the actual workers
func (ww *workerWatcher) WorkersList() []WorkerBase {
- ww.stack.mutex.Lock()
- defer ww.stack.mutex.Unlock()
- workersCopy := make([]WorkerBase, 0, 1)
- for _, v := range ww.stack.workers {
- sw := v.(SyncWorker)
- workersCopy = append(workersCopy, sw)
- }
-
- return workersCopy
+ return ww.stack.Workers()
}
func (ww *workerWatcher) wait(w WorkerBase) {