DWORD WorkerThread::work()
{
    _ASSERT(NULL != logger);
    while (!stopped)
    {
        for (int i = 0; i < executors_count; ++i)
        {
            executors_lock.lock();
            auto executor = task_executors[i];
            executors_lock.unlock();
            try
            {

                logger->add_message("Waiting for tasks...");
                bool tasks_ready = executor->wait_for_tasks(max_wait_ms);
                if (!tasks_ready) {
                    continue;
                }
                
                logger->add_message("...the wait is over");

                logger->add_message("Task >>started>>");
                bool has_more_tasks = executor->complete_next_task();
                if (has_more_tasks)
                {
                    logger->add_message("Task <<finished<<");
                }
                else
                {
                    logger->add_message("ALL Tasks ==finished==");
                }
            }
            catch (PhysicsError)
            {
                logger->add_message("ERROR while completing task, worker thread terminated!");
                executor->abort();
                return 1;
            }
            catch (DeadLockError)
            {
                logger->add_message("DEADLOCK detected, worker thread terminated!");
                return 2;
            }
        }
    }
    return 0;
}
Beispiel #2
0
static void run_one_test(struct perf_sched *sched)
{
	u64 T0, T1, delta, avg_delta, fluct;

	T0 = get_nsecs();
	wait_for_tasks(sched);
	T1 = get_nsecs();

	delta = T1 - T0;
	sched->sum_runtime += delta;
	sched->nr_runs++;

	avg_delta = sched->sum_runtime / sched->nr_runs;
	if (delta < avg_delta)
		fluct = avg_delta - delta;
	else
		fluct = delta - avg_delta;
	sched->sum_fluct += fluct;
	if (!sched->run_avg)
		sched->run_avg = delta;
	sched->run_avg = (sched->run_avg * 9 + delta) / 10;

	printf("#%-3ld: %0.3f, ", sched->nr_runs, (double)delta / 1000000.0);

	printf("ravg: %0.2f, ", (double)sched->run_avg / 1e6);

	printf("cpu: %0.2f / %0.2f",
		(double)sched->cpu_usage / 1e6, (double)sched->runavg_cpu_usage / 1e6);

#if 0
	/*
	 * rusage statistics done by the parent, these are less
	 * accurate than the sched->sum_exec_runtime based statistics:
	 */
	printf(" [%0.2f / %0.2f]",
		(double)sched->parent_cpu_usage/1e6,
		(double)sched->runavg_parent_cpu_usage/1e6);
#endif

	printf("\n");

	if (sched->nr_sleep_corrections)
		printf(" (%ld sleep corrections)\n", sched->nr_sleep_corrections);
	sched->nr_sleep_corrections = 0;
}