//-----------------------------------------------------------------------------
/// Wait for workers to finish and get their results.
/// \param pFrameProfiler Pointer to the frame profiler.
//-----------------------------------------------------------------------------
void VktTraceAnalyzerLayer::WaitAndFetchResults(VktFrameProfilerLayer* pFrameProfiler)
{
    // Gather all known queues
    std::vector<VktWrappedQueue*> queues;
    GetAvailableQueues(queues);

    if (queues.size() > 0)
    {
        std::vector<HANDLE> queueThreads;

        for (UINT i = 0; i < queues.size(); i++)
        {
            for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++)
            {
                VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j);

                if (pWorkerInfo != nullptr)
                {
                    queueThreads.push_back(queues[i]->GetThreadHandle(j));
                }
            }
        }

        const UINT queueWorkerCount = (UINT)queueThreads.size();

        // Gather all worker handles
        if (queueWorkerCount > 0)
        {
            // Wait for other workers
            DWORD retVal = WaitForMultipleObjects(queueWorkerCount, &queueThreads[0], TRUE, QUEUE_RESULTS_WORKER_TIMEOUT);

            if (WaitSucceeded(retVal, queueWorkerCount) == false)
            {
                Log(logWARNING, "Detected failure condition when waiting for worker threads.\n");
            }

            // Get results from thread
            for (UINT i = 0; i < queues.size(); i++)
            {
                for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++)
                {
                    VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j);

                    pFrameProfiler->VerifyAlignAndStoreResults(
                        queues[i],
                        pWorkerInfo->m_outputs.results,
                        &pWorkerInfo->m_inputs.timestampPair,
                        pWorkerInfo->m_threadInfo.workerThreadCountID,
                        mFramestartTime);
                }
            }

            // Close worker handles
            for (UINT i = 0; i < queues.size(); i++)
            {
                queues[i]->EndCollection();
            }
        }
    }
}
Example #2
0
File: app.c Project: Distrotech/ntp
isc_result_t
isc_app_run(void) {
	isc_event_t *event, *next_event;
	isc_task_t *task;
	HANDLE *pHandles = NULL;

	REQUIRE(main_thread == GetCurrentThread());
	LOCK(&lock);
	if (!running) {
		running = ISC_TRUE;

		/*
		 * Post any on-run events (in FIFO order).
		 */
		for (event = ISC_LIST_HEAD(on_run);
		     event != NULL;
		     event = next_event) {
			next_event = ISC_LIST_NEXT(event, ev_link);
			ISC_LIST_UNLINK(on_run, event, ev_link);
			task = event->ev_sender;
			event->ev_sender = NULL;
			isc_task_sendanddetach(&task, &event);
		}

	}

	UNLOCK(&lock);

	/*
	 * There is no danger if isc_app_shutdown() is called before we wait
	 * for events.
	 */

	while (!want_shutdown) {
		dwWaitResult = WaitForMultipleObjects(NUM_EVENTS, hEvents,
						      FALSE, INFINITE);

		/* See why we returned */
		
		if (WaitSucceeded(dwWaitResult, NUM_EVENTS)) {
			/*
			 * The return was due to one of the events
			 * being signaled
			 */
			switch (WaitSucceededIndex(dwWaitResult)) {
			case RELOAD_EVENT:
				want_reload = ISC_TRUE;
				break;

			case SHUTDOWN_EVENT:
				want_shutdown = ISC_TRUE;
				break;
			}
		}
		if (want_reload) {
			want_reload = ISC_FALSE;
			return (ISC_R_RELOAD);
		}

		if (want_shutdown && blocked)
			exit(-1);
	}

	return (ISC_R_SUCCESS);
}
Example #3
0
//-----------------------------------------------------------------------------
/// Wait for workers to finish and get their results.
/// \param pFrameProfiler Pointer to the frame profiler.
//-----------------------------------------------------------------------------
void VktTraceAnalyzerLayer::WaitAndFetchResults(VktFrameProfilerLayer* pFrameProfiler)
{
    // Gather all known queues
    std::vector<VktWrappedQueue*> queues;
    GetAvailableQueues(queues);

    if (queues.size() > 0)
    {
#if AMDT_BUILD_TARGET == AMDT_WINDOWS_OS
        std::vector<HANDLE> queueThreads;
#elif AMDT_BUILD_TARGET == AMDT_LINUX_OS
        std::vector<std::thread*> queueThreads;
#else
#error Unknown build target! No valid value for AMDT_BUILD_TARGET.
#endif

        for (UINT i = 0; i < queues.size(); i++)
        {
            for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++)
            {
                VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j);

                if (pWorkerInfo != nullptr)
                {
                    queueThreads.push_back(queues[i]->GetThreadHandle(j));
                }
            }
        }

        const UINT queueWorkerCount = (UINT)queueThreads.size();

        // Gather all worker handles
        if (queueWorkerCount > 0)
        {
            // Wait for other workers
#ifdef WIN32
            DWORD retVal = WaitForMultipleObjects(queueWorkerCount, &queueThreads[0], TRUE, QUEUE_RESULTS_WORKER_TIMEOUT);
#else

            for (size_t it = 0; it < queueWorkerCount; it++)
            {
                queueThreads[it]->join();
            }

            DWORD retVal = 0;
#endif

            if (WaitSucceeded(retVal, queueWorkerCount) == false)
            {
                Log(logWARNING, "Detected failure condition when waiting for worker threads.\n");
            }

            // Get results from thread
            for (UINT i = 0; i < queues.size(); i++)
            {
                for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++)
                {
                    VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j);

                    pFrameProfiler->VerifyAlignAndStoreResults(
                        queues[i],
                        pWorkerInfo->m_outputs.results,
                        &pWorkerInfo->m_inputs.timestampPair,
                        pWorkerInfo->m_threadInfo.workerThreadCountID,
                        pWorkerInfo->m_inputs.frameStartTime);
                }
            }

            // Close worker handles
            for (UINT i = 0; i < queues.size(); i++)
            {
                queues[i]->EndCollection();
            }
        }
    }
}