示例#1
0
void ThreadManager::execute(const unsigned int numThreads,
                            ThreadWorkerInterface &threadWorker) {

  if (numThreads == 1) {
    threadWorker.doWork(0);
  } else {
    ThreadFuncInput *threadFuncInput = new ThreadFuncInput[numThreads];
    threadIDs[0] = pthread_self();
    threadFuncInput[0].worker = &threadWorker;
    threadFuncInput[0].threadID = 0;

    for (unsigned int i = 1; i < numThreads; i++) {
      threadFuncInput[i].worker = &threadWorker;
      threadFuncInput[i].threadID = i;

      void *arg = &threadFuncInput[i];
      int info = pthread_create(&threadIDs[i], NULL, threadFunc, arg);
      if (info != 0) {
        threadIDs[i] = 0;
        //            	handle_error_en(info, "pthread_create");
      }
    }
    // execute the worker from the calling thread
    threadFunc(&threadFuncInput[0]);

    // Join all hreads
    for (int i = 1; i < numThreads; i++)
      if (threadIDs[i]) {
        void *exitPtr = NULL;
        int info = pthread_join(threadIDs[i], &exitPtr);
        threadIDs[i] = 0;
      }
    delete [] threadFuncInput;
  }
}
// ----------------------------------------------------------------------------
void KinectManager::update()
{
#ifndef KINECTMOTE_THREADING
    threadFunc();
#endif
	irr::SEvent event = m_kinect->getIrrEvent();
    input_manager->input(event);
}   
示例#3
0
// ----------------------------------------------------------------------------
void WiimoteManager::update()
{
#ifndef WIIMOTE_THREADING
    threadFunc();
#endif
    for(unsigned int i=0 ; i < m_wiimotes.size(); i++)
    {
        irr::SEvent event = m_wiimotes[i]->getIrrEvent();
        input_manager->input(event);
    }
}   // update
示例#4
0
文件: Threads.cpp 项目: GLolol/znc
void CThreadPool::addJob(CJob* job) {
    CMutexLocker guard(m_mutex);
    m_jobs.push_back(job);

    // Do we already have a thread which can handle this job?
    if (m_num_idle > 0) {
        m_cond.notify_one();
        return;
    }

    if (m_num_threads >= MAX_TOTAL_THREADS)
        // We can't start a new thread. The job will be handled once
        // some thread finishes its current job.
        return;

    // Start a new thread for our pool
    m_num_threads++;
    std::thread([this]() { threadFunc(); }).detach();
}
示例#5
0
	void Thread::init(ThreadFn _fn, void* _userData, uint32_t _stackSize, const char* _name)
	{
		BX_CHECK(!m_running, "Already running!");

		m_fn = _fn;
		m_userData = _userData;
		m_stackSize = _stackSize;
		m_running = true;

#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE
		m_handle = ::CreateThread(NULL
				, m_stackSize
				, (LPTHREAD_START_ROUTINE)threadFunc
				, this
				, 0
				, NULL
				);
#elif BX_PLATFORM_WINRT
		m_handle = CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS);
		auto workItemHandler = ref new WorkItemHandler([=](IAsyncAction^)
				{
				m_exitCode = threadFunc(this);
				SetEvent(m_handle);
				}, CallbackContext::Any);