eStatus GameManager::prepare() { eStatus status = STATUS_SUCCESS; // Load the game board from file status = m_gameBoard.prepare(); if (is_failed(status)) { return status; } // print the start positions. m_gameBoard.printBoard(); return status; }
static void advance_job(td_job_queue *queue, td_node *node, int job_id) { td_jobstate state; while ((state = node->job.state) < TD_JOB_COMPLETED) { switch (state) { case TD_JOB_INITIAL: if (node->job.block_count > 0) { /* enqueue any blocking jobs and transition to the blocked state */ int i, count, bc = 0; td_node **deps = node->deps; for (i = 0, count = node->dep_count; i < count; ++i) { td_node *dep = deps[i]; if (!is_completed(dep)) { ++bc; if (!is_queued(dep) && dep->job.state < TD_JOB_BLOCKED) enqueue(queue, dep); } } assert(bc == node->job.block_count); transition_job(queue, node, TD_JOB_BLOCKED); pthread_cond_broadcast(&queue->work_avail); return; } else { /* nothing is blocking this job, so scan implicit deps immediately */ transition_job(queue, node, TD_JOB_SCANNING); } break; case TD_JOB_BLOCKED: assert(0 == node->job.block_count); if (0 == node->job.failed_deps) transition_job(queue, node, TD_JOB_SCANNING); else transition_job(queue, node, TD_JOB_FAILED); break; case TD_JOB_SCANNING: if (0 == scan_implicit_deps(queue, node)) { update_input_signature(queue, node); if (is_up_to_date(queue, node)) transition_job(queue, node, TD_JOB_UPTODATE); else transition_job(queue, node, TD_JOB_RUNNING); } else { /* implicit dependency scanning failed */ transition_job(queue, node, TD_JOB_FAILED); } break; case TD_JOB_RUNNING: if (0 != run_job(queue, node, job_id)) transition_job(queue, node, TD_JOB_FAILED); else transition_job(queue, node, TD_JOB_COMPLETED); break; default: assert(0); td_croak("can't get here"); break; } } if (is_completed(node)) { int qcount = 0; td_job_chain *chain = node->job.pending_jobs; if (td_debug_check(queue->engine, TD_DEBUG_QUEUE)) printf("%s completed - enqueing blocked jobs\n", node->annotation); /* unblock all jobs that are waiting for this job and enqueue them */ while (chain) { td_node *n = chain->node; if (is_failed(node)) n->job.failed_deps++; /* nodes blocked on this node can't be completed yet */ assert(!is_completed(n)); if (0 == --n->job.block_count) { if (!is_queued(n)) enqueue(queue, n); ++qcount; } chain = chain->next; } if (1 < qcount) pthread_cond_broadcast(&queue->work_avail); else if (1 == qcount) pthread_cond_signal(&queue->work_avail); } }