コード例 #1
0
Dispatcher::~Dispatcher() {
  assert(GetCurrentThreadId() == threadId);
  for (NativeContext* context = contextGroup.firstContext; context != nullptr; context = context->groupNext) {
    interrupt(context);
  }

  yield();
  assert(timers.empty());
  assert(contextGroup.firstContext == nullptr);
  assert(contextGroup.firstWaiter == nullptr);
  assert(firstResumingContext == nullptr);
  assert(runningContextCount == 0);
  while (firstReusableContext != nullptr) {
    void* fiber = firstReusableContext->fiber;
    firstReusableContext = firstReusableContext->next;
    DeleteFiber(fiber);
  }

  int wsaResult = WSACleanup();
  assert(wsaResult == 0);
  BOOL result = CloseHandle(completionPort);
  assert(result == TRUE);
  result = ConvertFiberToThread();
  assert(result == TRUE);
  DeleteCriticalSection(reinterpret_cast<LPCRITICAL_SECTION>(criticalSection));
}
コード例 #2
0
ファイル: pthreads_win32.c プロジェクト: Ferada/sbcl
VOID CALLBACK Fiber_Function(LPVOID param)
{
  pthread_t self = (pthread_t) param;
  thread_or_fiber_function(param);
  {
    /* fiber_group is a main thread into which we are to call */
    pthread_t group = self->fiber_group;
    free(self);
    /* pthread_np_run_in_fiber (see below) normally switches back to
       caller. Nullify our identity, so it knows there is nothing to
       switch to, and continues running instead. */
    tls_impersonate(NULL);
    if (group) {
      /* Every running [pthread_create]d fiber runs in some thread
         that has its own pthread_self identity (that was created as
         thread and later converted to fiber). `group' field of
         running fiber always points to that other pthread.

         Now switch to our group ("current master fiber created as
         thread"), asking it to delete our (OS) fiber data with
         fiber_destructor. */
      pthread_np_run_in_fiber(group, fiber_destructor, GetCurrentFiber());
    }
    /* Within current pthread API we never end up here.

     BTW, if fibers are ever pooled, to avoid stack space reallocation
     etc, jumping to the beginning of Fiber_Function should be the
     thing to do here. */
    DeleteFiber(GetCurrentFiber()); /* Exits. See Thread_Function for
                                       explanation -- why not
                                       ExitThread. */
  }
}
コード例 #3
0
ファイル: context.cpp プロジェクト: Mirocow/balancer
TContMachineContext::~TContMachineContext() throw () {
    if (MainFiber_) {
        ConvertFiberToThread();
    } else {
        DeleteFiber(Fiber_);
    }
}
コード例 #4
0
ファイル: uthread_win32.cpp プロジェクト: ricky26/netlib
		void destroy() override
		{
			remove();
			DeleteFiber(fiber);
			fiber = nullptr;
			uthread::destroy();
		}
コード例 #5
0
ファイル: coroutine-win32.c プロジェクト: 0bliv10n/s2e
void qemu_coroutine_delete(Coroutine *co_)
{
    CoroutineWin32 *co = DO_UPCAST(CoroutineWin32, base, co_);

    DeleteFiber(co->fiber);
    g_free(co);
}
コード例 #6
0
ファイル: fiber.cpp プロジェクト: ximenpo/simple-cpp-win32
    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;
                }
            }
        }
    }
コード例 #7
0
FiberPool_::~FiberPool_()
{
	{
		std::lock_guard<std::mutex> lg(_clearMutex);
		_exitSign = true;
		if (_clearWait)
		{
			_clearWait = false;
			_clearVar.notify_one();
		}
	}
	_clearThread.join();

	int ic = 0;
	for (int i = 0; i < 256; i++)
	{
		std::lock_guard<std::mutex> lg1(_fiberPool[i]._mutex);
		while (!_fiberPool[i]._pool.empty())
		{
			coro_pull_interface* pull = _fiberPool[i]._pool.back();
			_fiberPool[i]._pool.pop_back();
			DeleteFiber(pull->_fiber._fiberHandle);
			delete pull;
			_stackCount--;
		}
	}
	assert(0 == _stackCount);
}
コード例 #8
0
        Fiber::~Fiber()
        {
#if defined(WINDOWS)
            if(m_fiber)
                DeleteFiber(m_fiber);
#endif
        }
コード例 #9
0
ファイル: taurus_imp.cpp プロジェクト: holyreaper/syyserver
inline int cleanup_coroutine(coroutine* c)
{
	DeleteFiber(c->ctx);
	c->ctx = 0;
	c->stk_size = 0;
	return 0;
}
コード例 #10
0
void Dispatcher::clear() {
  assert(GetCurrentThreadId() == threadId);
  while (firstReusableContext != nullptr) {
    void* fiber = firstReusableContext->fiber;
    firstReusableContext = firstReusableContext->next;
    DeleteFiber(fiber);
  }
}
コード例 #11
0
ファイル: Dispatcher.cpp プロジェクト: inmoney/bytecoin
void Dispatcher::clear() {
  assert(GetCurrentThreadId() == threadId);
  while (!reusableContexts.empty()) {
    DeleteFiber(reusableContexts.top());
    --contextCount;
    reusableContexts.pop();
  }
}
コード例 #12
0
TaskScheduler::~TaskScheduler() {
	delete[] m_threads;

	void *fiber;
	while (m_fiberPool.try_dequeue(fiber)) {
		DeleteFiber(fiber);
	}

	for (uint i = 0; i < m_numThreads; ++i) {
		DeleteFiber(m_fiberSwitchingFibers[i]);
		DeleteFiber(m_counterWaitingFibers[i]);
	}
	delete[] m_fiberSwitchingFibers;
	delete[] m_counterWaitingFibers;

	DeleteCriticalSection(&m_waitingTaskLock);
}
コード例 #13
0
//------------------------------------------------------------------------------
Fiber::~Fiber()
{
#if defined(__WIN32__) || defined(__WIN64__)
  if( fiber_ != NULL ) DeleteFiber(fiber_);
#endif
#if HAVE_UCONTEXT_H
  kfree(context_.uc_stack.ss_sp);
#endif
}
コード例 #14
0
int 
clemuKernelJob :: FreeJob(void)
{
int ret = CL_EMU_SUCCESS;

    for(int j = 0; j < m_nbr_active_group; j++)
	{
		  if ( m_groups[j].m_td_fibers )
		  {
		      for(int l = 0, tid = 0; l < m_nbr_wavefronts; l++)
		      {
			     int wf_sz = GetRealWFSz(l);
			     for(int m = 0; m < wf_sz; m++, tid++)
			     {
				     if ( m_groups[j].m_td_fibers[l*wf_sz + m].m_FIBER_id )
				     {
                         DeleteFiber(m_groups[j].m_td_fibers[l*wf_sz + m].m_FIBER_id);
					     m_groups[j].m_td_fibers[l*wf_sz + m].m_FIBER_id = 0;
				     }

			     }
		      }
	          delete [] m_groups[j].m_td_fibers;
		      m_groups[j].m_td_fibers = 0;
		  }

		  if ( m_groups[j].m_fiber.m_FIBER_id )
		  {
		      DeleteFiber(m_groups[j].m_fiber.m_FIBER_id);
		      m_groups[j].m_fiber.m_FIBER_id = 0;
		  }

          if ( m_groups[j].m_args )
		  {
			  delete [] m_groups[j].m_args;
			  m_groups[j].m_args = 0;
			  m_groups[j].m_nmb_arg = 0;
		  }

	}

   return(ret);

}
コード例 #15
0
sc_cor_fiber::~sc_cor_fiber()
{
    if( m_fiber != 0 ) {
#     ifdef WIN32
      PVOID cur_fiber = GetCurrentFiber();
      if (m_fiber != cur_fiber)
#     endif
	DeleteFiber( m_fiber );
    }
}
コード例 #16
0
ファイル: acid64.cpp プロジェクト: mwgoldsmith/sidplay2-libs
__declspec(dllexport) BOOL __stdcall closeC64 (handle_t handle)
{
    BEGIN (inst, handle)
    stop  (*inst.me);
    DeleteFiber (inst.engineFiber);
    delete &inst;
    return TRUE;
    END
    return FALSE;
}
コード例 #17
0
ファイル: cont.c プロジェクト: 0x00evil/ruby
static void
cont_free(void *ptr)
{
    RUBY_FREE_ENTER("cont");
    if (ptr) {
	rb_context_t *cont = ptr;
	RUBY_FREE_UNLESS_NULL(cont->saved_thread.stack); fflush(stdout);
#if FIBER_USE_NATIVE
	if (cont->type == CONTINUATION_CONTEXT) {
	    /* cont */
	    ruby_xfree(cont->ensure_array);
	    RUBY_FREE_UNLESS_NULL(cont->machine.stack);
	}
	else {
	    /* fiber */
	    rb_fiber_t *fib = (rb_fiber_t*)cont;
#ifdef _WIN32
	    if (GET_THREAD()->fiber != fib && cont->type != ROOT_FIBER_CONTEXT) {
		/* don't delete root fiber handle */
		rb_fiber_t *fib = (rb_fiber_t*)cont;
		if (fib->fib_handle) {
		    DeleteFiber(fib->fib_handle);
		}
	    }
#else /* not WIN32 */
	    if (GET_THREAD()->fiber != fib) {
                rb_fiber_t *fib = (rb_fiber_t*)cont;
                if (fib->ss_sp) {
                    if (cont->type == ROOT_FIBER_CONTEXT) {
			rb_bug("Illegal root fiber parameter");
                    }
		    munmap((void*)fib->ss_sp, fib->ss_size);
		}
	    }
            else {
		/* It may reached here when finalize */
		/* TODO examine whether it is a bug */
                /* rb_bug("cont_free: release self"); */
            }
#endif
	}
#else /* not FIBER_USE_NATIVE */
	ruby_xfree(cont->ensure_array);
	RUBY_FREE_UNLESS_NULL(cont->machine.stack);
#endif
#ifdef __ia64
	RUBY_FREE_UNLESS_NULL(cont->machine.register_stack);
#endif
	RUBY_FREE_UNLESS_NULL(cont->vm_stack);

	/* free rb_cont_t or rb_fiber_t */
	ruby_xfree(ptr);
    }
    RUBY_FREE_LEAVE("cont");
}
コード例 #18
0
/*
 * implementation for context_complete
 */
INLINE
void context_complete(sc_context *  pContext) {

  assert(pContext != NULL);

  if (pContext->pFiber != NULL) DeleteFiber(pContext->pFiber);
  if (pContext->pParameter != NULL) free(pContext->pParameter);
  pContext->pFiber     = NULL;
  pContext->pParameter = NULL;
  pContext->pRoutine   = NULL;
  pContext->state      = FS_COMPLETED;
  return;
}
コード例 #19
0
ファイル: mtarch.c プロジェクト: Asterios/contiki-econotag
/*--------------------------------------------------------------------------*/
void
mtarch_stop(struct mtarch_thread *thread)
{
#if defined(_WIN32) || defined(__CYGWIN__)

  DeleteFiber(thread->mt_thread);

#else /* _WIN32 || __CYGWIN__ */

  free(thread->mt_thread);

#endif /* _WIN32 || __CYGWIN__ */
}
コード例 #20
0
ファイル: mtarch.c プロジェクト: bocui107/freakz
/*--------------------------------------------------------------------------*/
void
mtarch_stop(struct mtarch_thread *thread)
{
#ifdef __CYGWIN__

  DeleteFiber(thread->mt_thread);

#else /* __CYGWIN__ */

  free(thread->mt_thread);

#endif /* __CYGWIN__ */
}
コード例 #21
0
NTSTATUS PhpTailQueryObjectHack(
    __out_opt PULONG ReturnLength
    )
{
    NTSTATUS status;
    LARGE_INTEGER timeout;

    PhQueryObjectContext.Initialized = TRUE;

    // Allow the worker thread to start.
    NtSetEvent(PhQueryObjectStartEvent, NULL);
    // Wait for the work to complete, with a timeout of 1 second.
    timeout.QuadPart = -1000 * PH_TIMEOUT_MS;
    status = NtWaitForSingleObject(PhQueryObjectCompletedEvent, FALSE, &timeout);

    PhQueryObjectContext.Initialized = FALSE;

    // Return normally if the work was completed.
    if (status == STATUS_WAIT_0)
    {
        ULONG returnLength;

        status = PhQueryObjectContext.Status;
        returnLength = PhQueryObjectContext.ReturnLength;

        PhReleaseQueuedLockExclusive(&PhQueryObjectMutex);

        if (ReturnLength)
            *ReturnLength = returnLength;

        return status;
    }
    // Kill the worker thread if it took too long.
    // else if (status == STATUS_TIMEOUT)
    else
    {
        // Kill the thread.
        if (NT_SUCCESS(NtTerminateThread(PhQueryObjectThreadHandle, STATUS_TIMEOUT)))
        {
            PhQueryObjectThreadHandle = NULL;

            // Delete the fiber (and free the thread stack).
            DeleteFiber(PhQueryObjectFiber);
            PhQueryObjectFiber = NULL;
        }

        PhReleaseQueuedLockExclusive(&PhQueryObjectMutex);

        return STATUS_UNSUCCESSFUL;
    }
}
コード例 #22
0
ファイル: fiber.cpp プロジェクト: ximenpo/simple-cpp-win32
    void do_delete_logic(WPARAM wParam, LPARAM lParam) {
        SCRIPT_LIST::iterator	it		= scripts_.begin();
        SCRIPT_LIST::iterator	it_end	= scripts_.end();

        for(; it != it_end; ++it) {
            FiberContextImpl*	pScript = static_cast<FiberContextImpl*>(*it);
            if(pScript->id_ == lParam) {
                DeleteFiber(pScript->fiber_);
                delete *it;
                scripts_.erase(it);
                break;
            }
        }
    }
コード例 #23
0
ファイル: fiber.cpp プロジェクト: rod-lin/ink
void InkCoro_Scheduler::schedule()
{
	do {
		pool[current]->state = INKCO_RUNNING;

		SwitchToFiber(pool[current]->fib);

		if (pool[current]->state == INKCO_DEAD) {
			DeleteFiber(pool[current]->fib);
			delete pool[current];
			pool[current] = NULL;
		}
	} while (switchRoutine());
	return;
}
コード例 #24
0
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
    // Reset data
    i = 0;
    memset( buffer, 0, sizeof(buffer) );

    // Convert this thread
    g_pFibers[FIBER_PRIMARY] = ConvertThreadToFiber( NULL );

    // Create the fibers
    g_pFibers[FIBER1] = CreateFiber( 0, Fiber1, NULL );
    g_pFibers[FIBER2] = CreateFiber( 0, Fiber2, NULL );

    // Execute the fibers
    SwitchToFiber( g_pFibers[FIBER1] );

    // Terminate the input
    buffer[i++] = '\0';

    DeleteFiber( g_pFibers[FIBER1] );
    DeleteFiber( g_pFibers[FIBER2] );

    OutputDebugString( buffer );
}
コード例 #25
0
ファイル: Coro.c プロジェクト: doublec/io
void Coro_setup(Coro *self, void *arg)
{
	// If this coro was recycled and already has a fiber, delete it.
	// Don't delete the main fiber. We don't want to commit suicide.

	if (self->fiber && !self->isMain)
	{
		DeleteFiber(self->fiber);
	}

	self->fiber = CreateFiber(Coro_stackSize(self),
							  (LPFIBER_START_ROUTINE)Coro_StartWithArg,
							 (LPVOID)arg);
	if (!self->fiber) {
		DWORD err = GetLastError();
		exit(err);
	}
}
コード例 #26
0
ファイル: Main.cpp プロジェクト: Alo81/scripthookvdotnet
BOOL WINAPI DllMain(HMODULE hModule, DWORD fdwReason, LPVOID lpvReserved)
{
	switch (fdwReason)
	{
		case DLL_PROCESS_ATTACH:
			DisableThreadLibraryCalls(hModule);
			scriptRegister(hModule, &ScriptMainSetup);
			keyboardHandlerRegister(&ScriptKeyboardMessage);
			break;
		case DLL_PROCESS_DETACH:
			DeleteFiber(sScriptFib);
			scriptUnregister(&ScriptMainSetup);
			keyboardHandlerUnregister(&ScriptKeyboardMessage);
			break;
	}

	return TRUE;
}
コード例 #27
0
ファイル: Dispatcher.cpp プロジェクト: inmoney/bytecoin
Dispatcher::~Dispatcher() {
  assert(resumingContexts.empty());
  assert(reusableContexts.size() == contextCount);
  assert(spawningProcedures.empty());
  assert(GetCurrentThreadId() == threadId);
  while (!reusableContexts.empty()) {
    DeleteFiber(reusableContexts.top());
    reusableContexts.pop();
  }

  int wsaResult = WSACleanup();
  assert(wsaResult == 0);
  BOOL result = CloseHandle(completionPort);
  assert(result == TRUE);
  result = CloseHandle(threadHandle);
  assert(result == TRUE);
  result = ConvertFiberToThread();
  assert(result == TRUE);
  DeleteCriticalSection(reinterpret_cast<LPCRITICAL_SECTION>(criticalSection));
}
コード例 #28
0
ファイル: pthreads_win32.c プロジェクト: Ferada/sbcl
/* Thread function for [pthread_create]d threads. Thread may become a
   fiber later, but (as stated above) it isn't supposed to be
   reattached to other system thread, even after it happens.
*/
DWORD WINAPI Thread_Function(LPVOID param)
{
  pthread_t self = (pthread_t) param;

  self->teb = NtCurrentTeb();
  thread_or_fiber_function(param);
  CloseHandle(self->handle);
  {
    void* fiber = self->fiber;
    free(self);
    if (fiber) {
      /* If thread was converted to fiber, deleting the fiber from
         itself exits the thread. There are some rumors on possible
         memory leaks if we just ExitThread or return here, hence the
         statement below. However, no memory leaks on bare ExitThread
         were observed yet. */
      DeleteFiber(GetCurrentFiber());
    }
  }
  return 0;
}
コード例 #29
0
ファイル: Coro.c プロジェクト: doublec/io
void Coro_free(Coro *self)
{
#ifdef USE_FIBERS
	// If this coro has a fiber, delete it.
	// Don't delete the main fiber. We don't want to commit suicide.
	if (self->fiber && !self->isMain)
	{
		DeleteFiber(self->fiber);
	}
#else
	STACK_DEREGISTER(self);
#endif
	if (self->stack)
	{
		io_free(self->stack);
	}

	//printf("Coro_%p io_free\n", (void *)self);

	io_free(self);
}
コード例 #30
0
ファイル: uthread_win32.cpp プロジェクト: ricky26/netlib
	void uthread::enter_thread()
	{
		uthread_impl *impl = new uthread_impl();
		void *f = ConvertThreadToFiber(impl);
		if(!f)
		{
			delete impl;
			DeleteFiber(f);
			return;
		}

		impl->fiber = f;

		if(!dry_thread)
		{
			dry_thread = uthread_create(uthread_dry, nullptr);
			dry_thread->mSuspended = true;
		}

		enter_thread_common();
	}