- add parentTask.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user