当前位置: 首页>>代码示例>>C++>>正文


C++ SwitchToFiber函数代码示例

本文整理汇总了C++中SwitchToFiber函数的典型用法代码示例。如果您正苦于以下问题:C++ SwitchToFiber函数的具体用法?C++ SwitchToFiber怎么用?C++ SwitchToFiber使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SwitchToFiber函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: clemu_groupthread_proc

static VOID 
__stdcall clemu_groupthread_proc ( LPVOID lpParameter )
{
clemuKernelGroup *group = (clemuKernelGroup *)lpParameter;
clemuKernelJob *job = (clemuKernelJob *)(group->GetParent());
int curwfid = 0;
//	while(true)
	{
       group->SetCurWF(curwfid);
// PROCESS GROUP HERE
       while(!group->IsEndof() || (job->GetNbrWavefronts() > curwfid) )
       {
            curwfid = group->GetCurWF();
// switch to the first thread of a wavefront
            SwitchToFiber(group->GetTFiber(curwfid, 0)->m_FIBER_id);

// select new wf
			curwfid = (group->IsEndof()) ? (curwfid + 1) : (curwfid + 1) % job->GetNbrWavefronts(); 
            group->SetCurWF(curwfid);

        }

// back to scheduler
        SwitchToFiber(job->GetFiber()->m_FIBER_id);
	}
   

}
开发者ID:Karma-Revolution,项目名称:ocl-emu,代码行数:28,代码来源:clemu_intnl.cpp

示例2: swap_context

      /*
       * Free function. Saves the current context in @p from
       * and restores the context in @p to. On windows the from
       * parameter is ignored. The current context is saved on the
       * current fiber.
       * Note that if the current thread is not a fiber, it will be
       * converted to fiber on the fly on call and unconverted before
       * return. This is expensive. The user should convert the
       * current thread to a fiber once on thread creation for better performance.
       * Note that we can't leave the thread unconverted on return or else we
       * will leak resources on thread destruction. Do the right thing by
       * default.
       */
      friend
      void
      swap_context(fibers_context_impl_base& from,
                   const fibers_context_impl_base& to,
                   default_hint)
      {
        if(!is_fiber()) {
          HPX_ASSERT(from.m_ctx == 0);
          from.m_ctx = ConvertThreadToFiber(0);
          HPX_ASSERT(from.m_ctx != 0);

#if HPX_HAVE_SWAP_CONTEXT_EMULATION != 0
          switch_to_fiber(to.m_ctx);
#else
          SwitchToFiber(to.m_ctx);
#endif
          BOOL result = ConvertFiberToThread();
          HPX_ASSERT(result);
          HPX_UNUSED(result);
          from.m_ctx = 0;
        } else {
          bool call_from_main = from.m_ctx == 0;
          if(call_from_main)
            from.m_ctx = GetCurrentFiber();
#if HPX_HAVE_SWAP_CONTEXT_EMULATION != 0
          switch_to_fiber(to.m_ctx);
#else
          SwitchToFiber(to.m_ctx);
#endif
          if(call_from_main)
            from.m_ctx = 0;
        }
      }
开发者ID:41i,项目名称:hpx,代码行数:46,代码来源:context_windows_fibers.hpp

示例3: assert

FiberPool_::coro_pull_interface* FiberPool_::getFiber(size_t size, void** sp, coro_handler h, void* param /*= NULL*/)
{
	assert(size && size % 4096 == 0 && size <= 1024 * 1024);
	void* currentFiber = NULL;
#if _WIN32_WINNT >= 0x0600
	if (IsThreadAFiber())
	{
		currentFiber = GetCurrentFiber();
	}
	else
	{
		currentFiber = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH);
	}
#else//#elif _MSC_VER >= 0x0501
	currentFiber = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH);
	if (!currentFiber)
	{
		currentFiber = GetCurrentFiber();
	}
#endif
	{
		fiber_pool_pck& pool = s_fiberPool._fiberPool[size / 4096 - 1];
		pool._mutex.lock();
		if (!pool._pool.empty())
		{
			coro_pull_interface* oldFiber = pool._pool.back();
			pool._pool.pop_back();
			pool._mutex.unlock();
			oldFiber->_fiber._pushHandle = currentFiber;
			oldFiber->_fiber._currentHandler = h;
			oldFiber->_fiber._fiberHandle->_param = param;
			oldFiber->_fiber._tick = 0;
			*sp = oldFiber->_fiber._fiberHandle->_stackTop;
			SwitchToFiber(oldFiber->_fiber._fiberHandle);
			return oldFiber;
		}
		pool._mutex.unlock();
	}
	s_fiberPool._stackCount++;
	s_fiberPool._stackTotalSize += size;
	coro_pull_interface* newFiber = new coro_pull_interface;
#ifdef _WIN64
	newFiber->_fiber._fiberHandle = (FiberStruct_*)CreateFiberEx(size, 64 * 1024, FIBER_FLAG_FLOAT_SWITCH, FiberPool_::fiberHandler, newFiber);
#else
	newFiber->_fiber._fiberHandle = (FiberStruct_*)CreateFiberEx(size, 0, FIBER_FLAG_FLOAT_SWITCH, FiberPool_::fiberHandler, newFiber);
#endif
	if (newFiber->_fiber._fiberHandle)
	{
		newFiber->_fiber._pushHandle = currentFiber;
		newFiber->_fiber._currentHandler = h;
		newFiber->_fiber._fiberHandle->_param = param;
		newFiber->_fiber._tick = 0;
		*sp = newFiber->_fiber._fiberHandle->_stackTop;
		SwitchToFiber(newFiber->_fiber._fiberHandle);
		return newFiber;
	}
	delete newFiber;
	throw std::shared_ptr<string>(new string("Fiber不足"));
}
开发者ID:askskype,项目名称:CPP-Actor-framework,代码行数:59,代码来源:fiber_pool.cpp

示例4: Fiber2

VOID __stdcall Fiber2( LPVOID lpParameter )
{
    buffer[i++] = '2';
    while( i < sizeof(buffer) - 1 )
    {
        buffer[i++] = 'a';
        SwitchToFiber( g_pFibers[FIBER1] );
    }

    SwitchToFiber( g_pFibers[FIBER_PRIMARY] );
}
开发者ID:karlgluck,项目名称:Evidyon,代码行数:11,代码来源:sandbox-main-fiber.cpp

示例5: FiberA

VOID WINAPI FiberA(DWORD)
{
	for (;;) {
		puts("A");
		SwitchToFiber(mainFiber);
		puts("B");
		SwitchToFiber(mainFiber);
		puts("C");
		SwitchToFiber(mainFiber);
	}
}
开发者ID:yorung,项目名称:MySnippets,代码行数:11,代码来源:Fiber.cpp

示例6: FiberB

VOID WINAPI FiberB(DWORD)
{
	for (;;) {
		puts("1");
		SwitchToFiber(mainFiber);
		puts("2");
		SwitchToFiber(mainFiber);
		puts("3");
		SwitchToFiber(mainFiber);
	}
}
开发者ID:yorung,项目名称:MySnippets,代码行数:11,代码来源:Fiber.cpp

示例7: main

int main(int argc, WCHAR* argv[])
{
	fiberA = CreateFiber(0, (LPFIBER_START_ROUTINE)FiberA, (LPVOID)0);
	fiberB = CreateFiber(0, (LPFIBER_START_ROUTINE)FiberB, (LPVOID)0);
	mainFiber = ConvertThreadToFiber(NULL);
	for (int i = 0; i < 20; i++) {
		SwitchToFiber(fiberA);
		SwitchToFiber(fiberB);
		Sleep(100);
	}
	return 0;
}
开发者ID:yorung,项目名称:MySnippets,代码行数:12,代码来源:Fiber.cpp

示例8: FiberFunc

void WINAPI FiberFunc(PVOID pvParam) {

   PFIBERINFO pFiberInfo = (PFIBERINFO) pvParam;
   
   /* Stores a value in the calling fiber's fiber local storage (FLS) slot 
    * for the specified FLS index. 
	* Each fiber has its own slot for each FLS index. */
   FlsSetValue(g_dwSlot, TEXT("Computation"));

   LogMessage(TEXT("entering computation..."));

   // Update the window showing which fiber is executing.
   SetDlgItemText(pFiberInfo->hwnd, IDC_FIBER, TEXT("Recalculation"));

   // Get the current count in the EDIT control.
   int nCount = GetDlgItemInt(pFiberInfo->hwnd, IDC_COUNT, NULL, FALSE);
   
   // Count from 0 to nCount, updating the STATIC control.
   for (int x = 0; x <= nCount; x++) {

      // UI events have higher priority than counting.
      // If there are any UI events, handle them ASAP.
      /* Retrieves the type of messages found in the calling thread's message queue. */
      if (HIWORD(GetQueueStatus(QS_ALLEVENTS)) != 0) {

         // The UI fiber has something to do; temporarily
         // pause counting and handle the UI events.
         SwitchToFiber(pFiberInfo->pFiberUI);

         // The UI has no more events; continue counting.
         SetDlgItemText(pFiberInfo->hwnd, IDC_FIBER, TEXT("Recalculation"));
      }

      // Update the STATIC control with the most recent count.
      SetDlgItemInt(pFiberInfo->hwnd, IDC_ANSWER, x, FALSE);

      // Sleep for a while to exaggerate the effect; remove 
      // the call to Sleep in production code.
      Sleep(200);
   }

   // Indicate that counting is complete.
   pFiberInfo->bps = BPS_DONE;

   // Reschedule the UI thread. When the UI thread is running
   // and has no events to process, the thread is put to sleep.
   // NOTE: If we just allow the fiber function to return,
   // the thread and the UI fiber die -- we don't want this!
   SwitchToFiber(pFiberInfo->pFiberUI);
}
开发者ID:melvinvarkey,项目名称:ANCI_C_Training,代码行数:50,代码来源:Counter.cpp

示例9: ConvertThreadToFiber

void
Processor::coreEntryPoint(Core *core)
{
   tCurrentCore = core;
   core->primaryFiber = ConvertThreadToFiber(NULL);

   while (mRunning) {
      std::unique_lock<std::mutex> lock(mMutex);

      if (auto fiber = peekNextFiber(core->id)) {
         // Remove fiber from schedule queue
         mFiberQueue.erase(std::remove(mFiberQueue.begin(), mFiberQueue.end(), fiber), mFiberQueue.end());

         // Switch to fiber
         core->currentFiber = fiber;
         fiber->coreID = core->id;
         fiber->parentFiber = core->primaryFiber;
         fiber->thread->state = OSThreadState::Running;
         lock.unlock();

         gLog->trace("Core {} enter thread {}", core->id, fiber->thread->id);
         SwitchToFiber(fiber->handle);
      } else {
         // Wait for a valid fiber
         gLog->trace("Core {} wait for thread", core->id);
         mCondition.wait(lock);
      }
   }
}
开发者ID:jskew,项目名称:wiiu-emu,代码行数:29,代码来源:processor.cpp

示例10: SwitchToFiber

// Return to the interrupted thread
void
Processor::finishInterrupt()
{
    auto core = tCurrentCore;
    auto fiber = core->interruptedFiber;

    core->currentFiber = fiber;
    core->interruptedFiber = nullptr;
    gLog->trace("Exit interrupt core {}", core->id);

    if (!fiber) {
        SwitchToFiber(core->primaryFiber);
    } else {
        SwitchToFiber(fiber->handle);
    }
}
开发者ID:archshift,项目名称:decaf-emu,代码行数:17,代码来源:processor.cpp

示例11: yield

	static void yield(YieldOperation &&yieldOperation)
	{
		Coroutine::Impl *pImpl = (Coroutine::Impl*)GetFiberData();
		pImpl->yieldOperation = &yieldOperation;
		assert(pImpl != nullptr);
		SwitchToFiber(pImpl->pReturnFiber);
	}
开发者ID:ennis,项目名称:rift,代码行数:7,代码来源:coroutine.cpp

示例12: coroutineEntry

	static void coroutineEntry()
	{
		Coroutine::Impl *pImpl = (Coroutine::Impl*)GetFiberData();
		pImpl->entry();
		pImpl->status = Coroutine::Status::Terminated;
		SwitchToFiber(pImpl->pReturnFiber);
	}
开发者ID:ennis,项目名称:rift,代码行数:7,代码来源:coroutine.cpp

示例13: do_update_logic

    void do_update_logic(WPARAM wParam, LPARAM lParam) {
        Impl::SCRIPT_END_HANDLER_LIST*	end_handlers	= reinterpret_cast<Impl::SCRIPT_END_HANDLER_LIST*>(lParam);
        {
            SCRIPT_LIST::iterator	it		= scripts_.begin();
            for(; it != scripts_.end(); ++it) {
                FiberContextImpl*	pScript = static_cast<FiberContextImpl*>(*it);
                if(pScript->is_running()) {
                    pScript->timestamp_	= timestamp_;
                    SwitchToFiber(pScript->fiber_);
                }
            }
        }

        {
            SCRIPT_LIST::iterator	it		= scripts_.begin();
            for(; it != scripts_.end(); ) {
                FiberContextImpl*	pScript = static_cast<FiberContextImpl*>(*it);
                if(!pScript->is_running() && (NULL != end_handlers)) {
                    if(pScript->callbacker_) {
                        FiberScriptEndHandler handler;
                        handler.id				= pScript->id_;
                        handler.param			= pScript->param_;
                        handler.handler			= pScript->callbacker_;
                        end_handlers->push_back(handler);
                    }

                    DeleteFiber(pScript->fiber_);
                    delete *it;
                    it = scripts_.erase(it);
                } else {
                    ++it;
                }
            }
        }
    }
开发者ID:ximenpo,项目名称:simple-cpp-win32,代码行数:35,代码来源:fiber.cpp

示例14: while

void __stdcall TaskScheduler::FiberSwitchStart(void *arg) {
	TaskScheduler *taskScheduler = (TaskScheduler *)arg;

	while (true) {
		taskScheduler->m_fiberPool.enqueue(tls_currentFiber);
		SwitchToFiber(tls_fiberToSwitchTo);
	}
}
开发者ID:galek,项目名称:FiberTaskingLib,代码行数:8,代码来源:task_scheduler.cpp

示例15: SwitchToFiber

void InkCoro_Scheduler::wrapper(LPVOID arg)
{
	InkCoro_Scheduler_wrapper_arg *tmp = (InkCoro_Scheduler_wrapper_arg *)arg;
	tmp->co->func(tmp->co->arg);
	tmp->sched->destroy(tmp->co);
	SwitchToFiber(tmp->sched->main_fib);
	return;
}
开发者ID:rod-lin,项目名称:ink,代码行数:8,代码来源:fiber.cpp


注:本文中的SwitchToFiber函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。