Пример #1
0
void CRhoThreadImpl::start(IRhoRunnable* pRunnable, IRhoRunnable::EPriority ePriority)
{
    m_hAwakeEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
	DWORD dwThreadID;
	m_hThread = ::CreateThread(NULL, 0, runProc, pRunnable, 0, &dwThreadID);
    setThreadPriority(ePriority);
}
Пример #2
0
void AbstractThread::setPriority( const int32_t priority )
{
    TLockMutex l( m_mutex );
    
    if ( isState( ThreadState_Running ) )
    {
        setThreadPriority( m_thread, priority );
    }
}
Пример #3
0
void CRhoThreadImpl::start(IRhoRunnable* pRunnable, IRhoRunnable::EPriority ePriority)
{
#if defined(OS_WP8)
	pRunnable->runObject();
#else
    DWORD dwThreadID;
    m_hThread = ::CreateThread(NULL, 0, runProc, pRunnable, 0, &dwThreadID);
    setThreadPriority(ePriority);
#endif
}
Пример #4
0
//==============================================================================
void Thread::startThread()
{
    const RecursiveMutex::ScopedLockType  sl (startStopLock);

    shouldExit = false;

    if (threadHandle == nullptr)
    {
        launchThread();
        setThreadPriority (threadHandle, threadPriority);
        startSuspensionEvent.signal();
    }
}
Пример #5
0
HANDLE WinThread::start(void*arg){
	traceFunction(eOS);
	this->arg(arg);
//	CreateMutex(0,false,0);
	IThreadManager::getInstance().preThreadStart();

	threadHandle = CreateThread(0,0,(LPTHREAD_START_ROUTINE)WinThread::entryPoint,this,0,&threadID);
	setThreadPriority(ETP_Normal);
	//Sleep(10);
	m_initSync.Block(2);
//	m_initSync->wait(m_initMutex);
	IThreadManager::getInstance().postThreadStart();
	
//	HANDLE code = _beginthreadex(0,0,(LPTHREAD_START_ROUTINE)WinThread::entryPoint,this,0,&threadID);
	return threadHandle;
}
Пример #6
0
//==============================================================================
bool Thread::setPriority (const int newPriority)
{
    // NB: deadlock possible if you try to set the thread prio from the thread itself,
    // so using setCurrentThreadPriority instead in that case.
    if (getCurrentThreadId() == getThreadId())
        return setCurrentThreadPriority (newPriority);

    const RecursiveMutex::ScopedLockType sl (startStopLock);

    if (setThreadPriority (threadHandle, newPriority))
    {
        threadPriority = newPriority;
        return true;
    }

    return false;
}
Пример #7
0
int CDMDebugFrame::run() {
	setThreadPriority(Thread::LOW);
	stop = false;

	while(true) {
		s.wait();
		if(stop)
			break;

		unique_ptr<string> x;
		if(!cmdList.pop(x)) {
			continue;
		}
		addLine(*x);
	}
		
	stop = false;
	return 0;
}
Пример #8
0
void *Seq::runThroughSequencer()
{
	LOG_INFO("Run through Seq");
    setThreadPriority();
	unsigned int tempI = 0;
	while(sequencerPlaying){
		if(currTime == -1L){
			currTime = getTimeInMillsec();
			triggerSample();
		}
		if((getTimeInMillsec()-currTime)>=incrementalNoteDuration){
			++tempI;
			seqI = tempI % numberOfNotes;
			triggerSample();
			currTime = getTimeInMillsec();
		}
	}
	currTime = -1L;
	seqI = 0;
	pthread_exit(NULL);
}
Пример #9
0
void *Seq::startSeqPrivate()
{
	LOG_INFO("Start Seq (private)");
	setThreadPriority();
	unsigned int tempI = 0;
	while(sequencerRunning){
		if(currTime == -1L){
			currTime = getTimeInMillsec();
			triggerSample();
		}
		if((getTimeInMillsec()-currTime)>=incrementalNoteDuration){
			++tempI;
			seqI = tempI % numberOfNotes;
			triggerSample();
			currTime = getTimeInMillsec();
		}
	}
	currTime = -1L;
	seqI = 0;
	pthread_exit(NULL);
}
Пример #10
0
void ShareManager::refresh(bool dirs, bool aUpdate, bool block, function<void (float)> progressF) noexcept {
	if(refreshing.test_and_set()) {
		LogManager::getInstance()->message(_("File list refresh in progress, please wait for it to finish before trying to refresh again"));
		return;
	}

	update = aUpdate;
	refreshDirs = dirs;

	join();

	if(block) {
		runRefresh(progressF);
	} else {
		try {
			start();
			setThreadPriority(Thread::LOW);
		} catch(const Exception &e) {
			LogManager::getInstance()->message(_("File list refresh failed: ") + e.getError());
		}
	}
}
Пример #11
0
bool Thread::setCurrentThreadPriority (const int newPriority)
{
    return setThreadPriority (0, newPriority);
}
Пример #12
0
void CRhoThreadImpl::start(IRhoRunnable* pRunnable, IRhoRunnable::EPriority ePriority)
{
    DWORD dwThreadID;
    //m_hThread = ::CreateThread(NULL, 0, runProc, pRunnable, 0, &dwThreadID);
    setThreadPriority(ePriority);
}
Пример #13
0
void setThreadPriority(Thread& t, ThreadPriority p){
	setThreadPriority(t.native_handle(), p);
}
Пример #14
0
void setThreadPriority(ThreadPriority p){
	setThreadPriority(pthread_self(), p);
}
Пример #15
0
void CRhoThreadImpl::start(IRhoRunnable* pRunnable, IRhoRunnable::EPriority ePriority)
{
    m_hThread = ::CreateThread(NULL, 0, runProc, pRunnable, 0, NULL);
    setThreadPriority(ePriority);
}
Пример #16
0
void setThreadPriority(ThreadPriority p){
	setThreadPriority(GetCurrentThread(), p);
}
Пример #17
0
void Updatable::loop()
{
    struct timeval last;
    struct timeval start;
    struct timeval profile; // last time a profile update happened
    Usec sleep_time;
    Usec offset;

    // This call determines the time it takes for a gettimeofday call
    // This makes the calls more accurate
    gettimeofday(&last, NULL);
    gettimeofday(&start, NULL);
    offset = timeval_diff(&start, &last);

    // Get time of day for profiling
    gettimeofday(&profile, NULL);
    m_profileCount = 0;

    // Zero last so we can check
    last.tv_usec = 0;
    
    while (1)
    {
        // Grab current time
        gettimeofday(&start, NULL);

        // Grab our running state
        bool in_background = false;
        int interval = 10;
        getState(in_background, interval);

        // Change thread state if needed
        {
            boost::mutex::scoped_lock lock(m_upStateMutex);
            if (m_settingChange & PRIORITY)
                setThreadPriority();

            if (m_settingChange & AFFINITY)
                setThreadAffinity();

            m_settingChange = 0;
        }
        
        if (in_background)
        {
            // On the first loop through, set the step to ideal
            double diff = (double)(interval *(double)1000);
            if (0 != last.tv_usec)
                diff = (double)(timeval_diff(&start, &last) + offset);

            // Record time for next run 
            last = start;
            
            // Call our update function
            update(diff / (double)1000000);
            m_profileCount += 1;

            Usec profile_time = timeval_diff(&last, &profile);
            // If 1 second has passed since the last profile, publish and reset
            if (profile_time > 1000000)
            {
                if (m_publisher) {
                    IntEventPtr event(new IntEvent());
                    event->data = m_profileCount;
                    m_publisher->publish(IUpdatable::PROFILE, event);
                }
                profile = last;
                m_profileCount = 0;
            }

            // Only sleep if we aren't running all out
            if (interval > 0)
            {
                // Determine next time to awake
                struct timeval next = start;
                timeval_add(&next, (Usec)interval * USEC_PER_MILLISEC);
            
                // Sleep for the rest for the remainder of our time
                sleep_time = -age(&next);

                // Handle overrun
                if (sleep_time < 0)
                    sleep_time = interval * USEC_PER_MILLISEC;

                // If the wait ends early keep waiting
                while(sleep_time > SLEEP_THRESHOLD)
                {
                    waitForUpdate((long)sleep_time);
                    sleep_time = -age(&next);
                }
            }
        }
        // Time to quit
        else
        {
            break;
        }
    }

    // Release an threads waiting on
    m_threadStopped.countDown();
}