| 217 | } |
| 218 | |
| 219 | JobSystemResult JobSystemSetParent(HJobContext context, HJob hchild, HJob hparent) |
| 220 | { |
| 221 | JobThreadContext* ctx = &context->m_ThreadContext; |
| 222 | DM_MUTEX_OPTIONAL_SCOPED_LOCK(ctx->m_Mutex); |
| 223 | |
| 224 | JobItem* item = CheckItem(ctx, hchild); |
| 225 | JobItem* parent = CheckItem(ctx, hparent); |
| 226 | |
| 227 | assert(item->m_Status == JOBSYSTEM_STATUS_CREATED); |
| 228 | assert(parent->m_Status <= JOBSYSTEM_STATUS_QUEUED); // If it has started to process, it's too late |
| 229 | |
| 230 | // You should only call setparent once per task |
| 231 | assert(item->m_Parent == INVALID_JOB); |
| 232 | assert(item->m_Sibling == INVALID_JOB); |
| 233 | |
| 234 | item->m_Parent = hparent; |
| 235 | item->m_Sibling = INVALID_JOB; |
| 236 | if (parent->m_FirstChild == INVALID_JOB) |
| 237 | { |
| 238 | parent->m_FirstChild = hchild; |
| 239 | parent->m_LastChild = hchild; |
| 240 | } |
| 241 | else |
| 242 | { |
| 243 | JobItem* last_child = GetJobItem(ctx, parent->m_LastChild); |
| 244 | last_child->m_Sibling = hchild; |
| 245 | parent->m_LastChild = hchild; |
| 246 | } |
| 247 | dmAtomicIncrement32(&parent->m_NumChildren); |
| 248 | |
| 249 | // TODO: Make sure all the children inherit the priority of the parent |
| 250 | |
| 251 | return JOBSYSTEM_RESULT_OK; |
| 252 | } |
| 253 | |
| 254 | HJob JobSystemCreateJob(HJobContext context, Job* job) |
| 255 | { |