示例#1
0
// run thread function in same thread
void RunSameThreadOn(int workcnt, qboolean showpacifier, void(*threadfunc)(int))
{
	int	start, end;

	if( numthreads <= 0 )
		ThreadSetDefault();
	if ( threaded == qtrue )
		Error("RunSameThreadOn: recursively entered!");

	start = I_FloatTime ();
	dispatch = 0;
	workcount = workcnt;
	oldf = -1;
	pacifier = showpacifier;
	threadfunc(0);
	end = I_FloatTime ();
	if (pacifier == qtrue)
	{
		while (oldf < 9)
		{
			oldf++;
			Sys_Printf ("%i...", oldf);
		}
		Sys_Printf (" (%i)\n", end-start);
	}
}
void Thread::threadLauncher(void *(*threadfunc)(void*), void *argv)
{
    void *result=0;
    #ifdef __NO_EXCEPTIONS
    result=threadfunc(argv);
    #else //__NO_EXCEPTIONS
    try {
        result=threadfunc(argv);
    } catch(std::exception& e)
    {
        errorHandler(PROPAGATED_EXCEPTION);
        errorLog("what():");
        errorLog(e.what());
        errorLog("\r\n");
    } catch(...)
    {
        errorHandler(PROPAGATED_EXCEPTION);
    }
    #endif //__NO_EXCEPTIONS
    //Thread returned from its entry point, so delete it

    //Since the thread is running, it cannot be in the sleeping_list, so no need
    //to remove it from the list
    {
        FastInterruptDisableLock lock;
        const_cast<Thread*>(cur)->flags.IRQsetDeleted();

        if(const_cast<Thread*>(cur)->flags.isDetached()==false)
        {
            //If thread is joinable, handle join
            if(cur->joinData.waitingForJoin!=NULL)
            {
                //Wake thread
                cur->joinData.waitingForJoin->flags.IRQsetJoinWait(false);
            }
            //Set result
            cur->joinData.result=result;
        } else {
            //If thread is detached, memory can be deallocated immediately
            exist_deleted=true;
        }
    }
    Thread::yield();//Since the thread is now deleted, yield immediately.
    //Will never reach here
    errorHandler(UNEXPECTED);
    
}
示例#3
0
void ProcessWorkQueueOnThreadWhile(PrioritizedWorkQueue *wq) {
	workThread = new std::thread(
#if defined(__SYMBIAN32__) || defined(MAEMO) || defined(MEEGO_EDITION_HARMATTAN) || defined(BLACKBERRY)
		[wq](){threadfunc(wq);}
#else
		std::bind(&threadfunc, wq)
#endif
	);
}
示例#4
0
文件: thread.cpp 项目: Albermg7/boost
        static OSStatus thread_proxy(void* param)
#endif
    {
        try
        {
            thread_param* p = static_cast<thread_param*>(param);
            boost::function0<void> threadfunc = p->m_threadfunc;
            p->started();
            threadfunc();
#if defined(BOOST_HAS_WINTHREADS)
            on_thread_exit();
#endif
        }
        catch (...)
        {
#if defined(BOOST_HAS_WINTHREADS)
            on_thread_exit();
#endif
        }
#if defined(BOOST_HAS_MPTASKS)
        ::boost::detail::thread_cleanup();
#endif
        return 0;
    }