- add parentTask.

This commit is contained in:
gazebo
2018-10-24 11:11:40 +08:00
parent f050ec926b
commit 5811d3cb68
12 changed files with 45 additions and 35 deletions

View File

@@ -60,17 +60,24 @@ func (ctx *Context) GetRootTask() tasksch.ITask {
return ctx.rootTask
}
func (ctx *Context) SetTaskOrAddChild(task tasksch.ITask) bool {
ctx.locker.Lock()
func (ctx *Context) SetTaskOrAddChild(task tasksch.ITask, parentTask tasksch.ITask) bool {
if parentTask != nil {
parentTask.AddChild(task)
} else {
parentTask = task
}
ctx.locker.RLock()
if ctx.rootTask == nil {
ctx.rootTask = task
ctx.locker.RUnlock()
ctx.locker.Lock()
if ctx.rootTask == nil {
ctx.rootTask = parentTask
}
ctx.locker.Unlock()
return true
}
ctx.locker.Unlock()
ctx.rootTask.AddChild(task)
ctx.locker.RUnlock()
return false
}