Merge pull request #14 from alitto/bug/fix-waiting-count

Prevent WaitingTasks counter to wrap around and upgrade to Go v1.16
This commit is contained in:
Alejandro Durante
2021-07-10 10:57:27 -03:00
committed by GitHub
7 changed files with 18 additions and 15 deletions
+1
View File
@@ -11,6 +11,7 @@ go:
- 1.13.x - 1.13.x
- 1.14.x - 1.14.x
- 1.15.x - 1.15.x
- 1.16.x
# Enable Go Modules # Enable Go Modules
env: env:
+2 -2
View File
@@ -1,9 +1,9 @@
module github.com/alitto/pond/examples/dynamic_size module github.com/alitto/pond/examples/dynamic_size
go 1.15 go 1.16
require ( require (
github.com/alitto/pond v1.5.0 github.com/alitto/pond v1.5.1
) )
replace github.com/alitto/pond => ../../ replace github.com/alitto/pond => ../../
+2 -2
View File
@@ -1,9 +1,9 @@
module github.com/alitto/pond/examples/fixed_size module github.com/alitto/pond/examples/fixed_size
go 1.15 go 1.16
require ( require (
github.com/alitto/pond v1.5.0 github.com/alitto/pond v1.5.1
) )
replace github.com/alitto/pond => ../../ replace github.com/alitto/pond => ../../
+2 -2
View File
@@ -1,9 +1,9 @@
module github.com/alitto/pond/examples/fixed_size module github.com/alitto/pond/examples/fixed_size
go 1.15 go 1.16
require ( require (
github.com/alitto/pond v1.5.0 github.com/alitto/pond v1.5.1
github.com/prometheus/client_golang v1.9.0 github.com/prometheus/client_golang v1.9.0
) )
+2 -2
View File
@@ -1,9 +1,9 @@
module github.com/alitto/pond/examples/task_group module github.com/alitto/pond/examples/task_group
go 1.15 go 1.16
require ( require (
github.com/alitto/pond v1.5.0 github.com/alitto/pond v1.5.1
) )
replace github.com/alitto/pond => ../../ replace github.com/alitto/pond => ../../
+1 -1
View File
@@ -1,3 +1,3 @@
module github.com/alitto/pond module github.com/alitto/pond
go 1.15 go 1.16
+8 -6
View File
@@ -211,13 +211,15 @@ func (p *WorkerPool) submit(task func(), canWaitForIdleWorker bool) (submitted b
return false return false
} }
defer func() { // Increment submitted and waiting task counters as soon as we receive a task
if submitted { atomic.AddUint64(&p.submittedTaskCount, 1)
// Increment submitted task count atomic.AddUint64(&p.waitingTaskCount, 1)
atomic.AddUint64(&p.submittedTaskCount, 1)
// Increment waiting task count defer func() {
atomic.AddUint64(&p.waitingTaskCount, 1) if !submitted {
// Task was not sumitted to the pool, decrement submitted and waiting task counters
atomic.AddUint64(&p.submittedTaskCount, ^uint64(0))
atomic.AddUint64(&p.waitingTaskCount, ^uint64(0))
} }
}() }()