Exemplo n.º 1
0
void Thread::suspendAllThreads() {
    Thread* thread;
    isAllThreadsSuspended = true;

    for(unsigned int i= 0; i < threads.size(); i++) {
        thread=threads.get(i);

        if(thread!=NULL &&
           (thread->id != thread_self->id) && thread->state == THREAD_RUNNING){
            suspendThread(thread);
            waitForThreadSuspend(thread);
        }
    }
}
void ThreadedTaskHandler::executeThread(void)
{
	while(!ExitRequested)
	{
		suspendThread();
		
		while(!ExitRequested && !TaskList.empty())
		{
			gprintf("\n\tThreadedTaskHandler::execute() TaskList.front");
			TaskList.front()->Execute();
			TaskList.pop();
		}
	}
}
Exemplo n.º 3
0
void SoundHandler::executeThread()
{
    //! initialize 48 kHz renderer
    u32 params[3] = { 1, 0, 0 };
    AXInitWithParams(params);


	for(u32 i = 0; i < MAX_DECODERS; ++i)
    {
        int priority = (MAX_DECODERS - 1 - i) * (Voice::PRIO_MAX - Voice::PRIO_MIN)  / (MAX_DECODERS - 1);
        voiceList[i] = new Voice(priority); // allocate voice 0 with highest priority
    }

    AXRegisterFrameCallback((void*)&axFrameCallback);


	u16 i = 0;
	while (!ExitRequested)
	{
		suspendThread();

		for(i = 0; i < MAX_DECODERS; ++i)
		{
			if(DecoderList[i] == NULL)
				continue;

			Decoding = true;
			if(DecoderList[i])
                DecoderList[i]->Lock();
			if(DecoderList[i])
                DecoderList[i]->Decode();
			if(DecoderList[i])
                DecoderList[i]->Unlock();
		}
		Decoding = false;
	}

	for(u32 i = 0; i < MAX_DECODERS; ++i)
        voiceList[i]->stop();

    AXRegisterFrameCallback(NULL);
    AXQuit();

	for(u32 i = 0; i < MAX_DECODERS; ++i)
        delete voiceList[i];
}
Exemplo n.º 4
0
void MachineThreads::gatherFromOtherThread(ConservativeRoots& conservativeRoots, Thread* thread)
{
    suspendThread(thread->platformThread);

    PlatformThreadRegisters regs;
    size_t regSize = getPlatformThreadRegisters(thread->platformThread, regs);

    conservativeRoots.add(static_cast<void*>(&regs), static_cast<void*>(reinterpret_cast<char*>(&regs) + regSize));

    void* stackPointer = otherThreadStackPointer(regs);
    void* stackBase = thread->stackBase;
    swapIfBackwards(stackPointer, stackBase);
    conservativeRoots.add(stackPointer, stackBase);

    resumeThread(thread->platformThread);

    freePlatformThreadRegisters(regs);
}
Exemplo n.º 5
0
void AsyncDeleter::executeThread(void)
{
    while(!exitApplication)
    {
        suspendThread();

        //! delete elements that require post process deleting
        //! because otherwise they would block or do invalid access on GUI thread
        while(!realDeleteElements.empty())
        {
            deleteMutex.lock();
            AsyncDeleter::Element *element = realDeleteElements.front();
            realDeleteElements.pop();
            deleteMutex.unlock();

            delete element;
        }
    }

}
Exemplo n.º 6
0
void Thread::waitForThreadSuspend(Thread *thread) {
    const int sMaxRetries = 10000000;
    const int sMaxSpinCount = 25;

    int spinCount = 0;
    int retryCount = 0;

    suspendThread(thread);
    while (thread->state == THREAD_RUNNING && !thread->suspended)
    {
        if (retryCount++ == sMaxRetries)
        {
            retryCount = 0;
            if(++spinCount >= sMaxSpinCount)
            {
                return; // give up
            } else if(thread->state >= THREAD_SUSPENDED)
                return;
        }
    }
}
void MachineThreads::gatherConservativeRoots(ConservativeRoots& conservativeRoots, void* stackCurrent)
{
    gatherFromCurrentThread(conservativeRoots, stackCurrent);

    if (m_threadSpecific) {
        PlatformThread currentPlatformThread = getCurrentPlatformThread();

        MutexLocker lock(m_registeredThreadsMutex);

#ifndef NDEBUG
        // Forbid malloc during the gather phase. The gather phase suspends
        // threads, so a malloc during gather would risk a deadlock with a
        // thread that had been suspended while holding the malloc lock.
        fastMallocForbid();
#endif
        for (Thread* thread = m_registeredThreads; thread; thread = thread->next) {
            if (!equalThread(thread->platformThread, currentPlatformThread))
                suspendThread(thread->platformThread);
        }

        // It is safe to access the registeredThreads list, because we earlier asserted that locks are being held,
        // and since this is a shared heap, they are real locks.
        for (Thread* thread = m_registeredThreads; thread; thread = thread->next) {
            if (!equalThread(thread->platformThread, currentPlatformThread))
                gatherFromOtherThread(conservativeRoots, thread);
        }

        for (Thread* thread = m_registeredThreads; thread; thread = thread->next) {
            if (!equalThread(thread->platformThread, currentPlatformThread))
                resumeThread(thread->platformThread);
        }

#ifndef NDEBUG
        fastMallocAllow();
#endif
    }
}