Beispiel #1
0
//++ ------------------------------------------------------------------------------------
// Details: This function forms a small management routine, to handle the thread's running.
// Type:    Method.
// Args:    None.
// Return:  None.
// Throws:  None.
//--
void
CMIUtilThreadActiveObjBase::ThreadManage()
{
    bool bAlive = true;

    // Infinite loop
    while (bAlive)
    {
        // Scope the lock while we access m_isDying
        {
            // Lock down access to the interface
            CMIUtilThreadLock serial(m_mutex);

            // Quit the run loop if we are dying
            if (m_references == 0)
                break;
        }
        // Execute the run routine
        if (!ThreadRun(bAlive))
            // Thread's run function failed (MIstatus::failure)
            break;

        // We will die if we have been signaled to die
        bAlive &= !m_bHasBeenKilled;
    }

    // Execute the finish routine just before we die
    // to give the object a chance to clean up
    ThreadFinish();

    m_thread.Finish();
}
Beispiel #2
0
abyss_bool
ConnProcess(TConn * const connectionP) {
    /*----------------------------------------------------------------------------
       Drive the main processing of a connection -- run the connection's
       "job" function, which should read HTTP requests from the connection
       and send HTTP responses.

       If we succeed, we guarantee the connection's "done" function will get
       called some time after all processing is complete.  It might be before
       we return or some time after.  If we fail, we guarantee the "done"
       function will not be called.
    -----------------------------------------------------------------------------*/
    abyss_bool retval;

    if (connectionP->hasOwnThread) {
        /* There's a background thread to handle this connection.  Set
           it running.
        */
        retval = ThreadRun(connectionP->threadP);
    } else {
        /* No background thread.  We just handle it here while Caller waits. */
        (connectionP->job)(connectionP);
        connDone(connectionP);
        retval = TRUE;
    }
    return retval;
}
Tid ULT_Switch(Thread *target)
{
	//printf("Trying to switch to thread with Tid[%d, context:[0x%.8x]\n", target->id, (int) target->context);
	ULT_Maintainence();
	doneThat = 0;
	assert(runningThread->context);
	getcontext(runningThread->context);
	if(!doneThat)
	{
		doneThat = 1;
		runningThread = target;
		//printf("Switched to thread with Tid[%d]\n", target->id);
		ThreadRun(runningThread);
		assert(0);
	}
	return target->id;
}
Beispiel #4
0
void CoWork::Pool::InitThreads(int nthreads)
{
	LLOG("Pool::InitThreads: " << nthreads);
	for(int i = 0; i < nthreads; i++)
		CHECK(threads.Add().Run([=] { worker_index = i; ThreadRun(i); }, true));
}