mirror of
https://github.com/safing/portbase
synced 2025-09-01 10:09:50 +00:00
Remove modules integration of taskmanager
This commit is contained in:
parent
cb94a48a29
commit
d86cccbbb6
3 changed files with 31 additions and 28 deletions
|
@ -3,7 +3,6 @@
|
||||||
package taskmanager
|
package taskmanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Safing/safing-core/modules"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -14,19 +13,23 @@ import (
|
||||||
// (1) panic: sync: WaitGroup is reused before previous Wait has returned - should theoretically not happen
|
// (1) panic: sync: WaitGroup is reused before previous Wait has returned - should theoretically not happen
|
||||||
// (2) sometimes there seems to some kind of race condition stuff, the test hangs and does not complete
|
// (2) sometimes there seems to some kind of race condition stuff, the test hangs and does not complete
|
||||||
|
|
||||||
var microTasksModule *modules.Module
|
var (
|
||||||
var closedChannel chan bool
|
closedChannel chan bool
|
||||||
|
|
||||||
var tasks *int32
|
tasks *int32
|
||||||
|
|
||||||
var mediumPriorityClearance chan bool
|
mediumPriorityClearance chan bool
|
||||||
var lowPriorityClearance chan bool
|
lowPriorityClearance chan bool
|
||||||
var veryLowPriorityClearance chan bool
|
veryLowPriorityClearance chan bool
|
||||||
|
|
||||||
var tasksDone chan bool
|
tasksDone chan bool
|
||||||
var tasksDoneFlag *abool.AtomicBool
|
tasksDoneFlag *abool.AtomicBool
|
||||||
var tasksWaiting chan bool
|
tasksWaiting chan bool
|
||||||
var tasksWaitingFlag *abool.AtomicBool
|
tasksWaitingFlag *abool.AtomicBool
|
||||||
|
|
||||||
|
shutdownSignal = make(chan struct{}, 0)
|
||||||
|
suttingDown = abool.NewBool(false)
|
||||||
|
)
|
||||||
|
|
||||||
// StartMicroTask starts a new MicroTask. It will start immediately.
|
// StartMicroTask starts a new MicroTask. It will start immediately.
|
||||||
func StartMicroTask() {
|
func StartMicroTask() {
|
||||||
|
@ -50,7 +53,7 @@ func newTaskIsWaiting() {
|
||||||
|
|
||||||
// StartMediumPriorityMicroTask starts a new MicroTask (waiting its turn) if channel receives.
|
// StartMediumPriorityMicroTask starts a new MicroTask (waiting its turn) if channel receives.
|
||||||
func StartMediumPriorityMicroTask() chan bool {
|
func StartMediumPriorityMicroTask() chan bool {
|
||||||
if !microTasksModule.Active.IsSet() {
|
if suttingDown.IsSet() {
|
||||||
return closedChannel
|
return closedChannel
|
||||||
}
|
}
|
||||||
if tasksWaitingFlag.SetToIf(false, true) {
|
if tasksWaitingFlag.SetToIf(false, true) {
|
||||||
|
@ -61,7 +64,7 @@ func StartMediumPriorityMicroTask() chan bool {
|
||||||
|
|
||||||
// StartLowPriorityMicroTask starts a new MicroTask (waiting its turn) if channel receives.
|
// StartLowPriorityMicroTask starts a new MicroTask (waiting its turn) if channel receives.
|
||||||
func StartLowPriorityMicroTask() chan bool {
|
func StartLowPriorityMicroTask() chan bool {
|
||||||
if !microTasksModule.Active.IsSet() {
|
if suttingDown.IsSet() {
|
||||||
return closedChannel
|
return closedChannel
|
||||||
}
|
}
|
||||||
if tasksWaitingFlag.SetToIf(false, true) {
|
if tasksWaitingFlag.SetToIf(false, true) {
|
||||||
|
@ -72,7 +75,7 @@ func StartLowPriorityMicroTask() chan bool {
|
||||||
|
|
||||||
// StartVeryLowPriorityMicroTask starts a new MicroTask (waiting its turn) if channel receives.
|
// StartVeryLowPriorityMicroTask starts a new MicroTask (waiting its turn) if channel receives.
|
||||||
func StartVeryLowPriorityMicroTask() chan bool {
|
func StartVeryLowPriorityMicroTask() chan bool {
|
||||||
if !microTasksModule.Active.IsSet() {
|
if suttingDown.IsSet() {
|
||||||
return closedChannel
|
return closedChannel
|
||||||
}
|
}
|
||||||
if tasksWaitingFlag.SetToIf(false, true) {
|
if tasksWaitingFlag.SetToIf(false, true) {
|
||||||
|
@ -81,9 +84,17 @@ func StartVeryLowPriorityMicroTask() chan bool {
|
||||||
return veryLowPriorityClearance
|
return veryLowPriorityClearance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func start() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func stop() error {
|
||||||
|
close(shutdownSignal)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
microTasksModule = modules.Register("Taskmanager:MicroTasks", 3)
|
|
||||||
closedChannel = make(chan bool, 0)
|
closedChannel = make(chan bool, 0)
|
||||||
close(closedChannel)
|
close(closedChannel)
|
||||||
|
|
||||||
|
@ -107,7 +118,7 @@ func init() {
|
||||||
for {
|
for {
|
||||||
|
|
||||||
// wait for an event to start new tasks
|
// wait for an event to start new tasks
|
||||||
if microTasksModule.Active.IsSet() {
|
if !suttingDown.IsSet() {
|
||||||
|
|
||||||
// reset timer
|
// reset timer
|
||||||
// https://golang.org/pkg/time/#Timer.Reset
|
// https://golang.org/pkg/time/#Timer.Reset
|
||||||
|
@ -124,7 +135,7 @@ func init() {
|
||||||
}
|
}
|
||||||
case <-time.After(timoutTimerDuration):
|
case <-time.After(timoutTimerDuration):
|
||||||
case <-tasksDone:
|
case <-tasksDone:
|
||||||
case <-microTasksModule.Stop:
|
case <-shutdownSignal:
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,7 +147,7 @@ func init() {
|
||||||
<-tasksDone
|
<-tasksDone
|
||||||
}
|
}
|
||||||
// signal module completion
|
// signal module completion
|
||||||
microTasksModule.StopComplete()
|
// microTasksModule.StopComplete()
|
||||||
// exit
|
// exit
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ package taskmanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"github.com/Safing/safing-core/modules"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/tevino/abool"
|
"github.com/tevino/abool"
|
||||||
|
@ -110,8 +109,6 @@ func fireNextTask() {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
module := modules.Register("Taskmanager:QueuedTasks", 3)
|
|
||||||
|
|
||||||
taskQueue = list.New()
|
taskQueue = list.New()
|
||||||
prioritizedTaskQueue = list.New()
|
prioritizedTaskQueue = list.New()
|
||||||
addToQueue = make(chan *Task, 1)
|
addToQueue = make(chan *Task, 1)
|
||||||
|
@ -128,9 +125,8 @@ func init() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-module.Stop:
|
case <-shutdownSignal:
|
||||||
// TODO: work off queue?
|
// TODO: work off queue?
|
||||||
module.StopComplete()
|
|
||||||
return
|
return
|
||||||
case <-getQueueLengthREQ:
|
case <-getQueueLengthREQ:
|
||||||
// TODO: maybe clean queues before replying
|
// TODO: maybe clean queues before replying
|
||||||
|
|
|
@ -4,7 +4,6 @@ package taskmanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"github.com/Safing/safing-core/modules"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,8 +45,6 @@ func waitUntilNextScheduledTask() <-chan time.Time {
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
module := modules.Register("Taskmanager:ScheduledTasks", 3)
|
|
||||||
|
|
||||||
taskSchedule = list.New()
|
taskSchedule = list.New()
|
||||||
addToSchedule = make(chan *Task, 1)
|
addToSchedule = make(chan *Task, 1)
|
||||||
waitForever = make(chan time.Time, 1)
|
waitForever = make(chan time.Time, 1)
|
||||||
|
@ -59,8 +56,7 @@ func init() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-module.Stop:
|
case <-shutdownSignal:
|
||||||
module.StopComplete()
|
|
||||||
return
|
return
|
||||||
case <-getScheduleLengthREQ:
|
case <-getScheduleLengthREQ:
|
||||||
// TODO: maybe clean queues before replying
|
// TODO: maybe clean queues before replying
|
||||||
|
|
Loading…
Add table
Reference in a new issue