Exemple #1
0
bool Threading::Mutex::Acquire( const wxTimeSpan& timeout )
{
#if wxUSE_GUI
	if( !wxThread::IsMain() || (wxTheApp == NULL) )
	{
		return AcquireWithoutYield(timeout);
	}
	else if( _WaitGui_RecursionGuard( L"Mutex::TimedAcquire" ) )
	{
		ScopedBusyCursor hourglass( Cursor_ReallyBusy );
		return AcquireWithoutYield( timeout );
	}
	else
	{
		//ScopedBusyCursor hourglass( Cursor_KindaBusy );
		wxTimeSpan countdown( (timeout) );

		do {
			if( AcquireWithoutYield( def_yieldgui_interval ) ) break;
			YieldToMain();
			countdown -= def_yieldgui_interval;
		} while( countdown.GetMilliseconds() > 0 );

		return countdown.GetMilliseconds() > 0;
	}

#else
	return AcquireWithoutYield();
#endif
}
Exemple #2
0
// This is a wxApp-safe implementation of Wait, which makes sure and executes the App's
// pending messages *if* the Wait is performed on the Main/GUI thread.  This ensures that
// user input continues to be handled and that windoes continue to repaint.  If the Wait is
// called from another thread, no message pumping is performed.
//
void Threading::Semaphore::Wait()
{
#if wxUSE_GUI
    if (!wxThread::IsMain() || (wxTheApp == NULL)) {
        sem_wait(&m_sema);
    } else if (_WaitGui_RecursionGuard(L"Semaphore::Wait")) {
        ScopedBusyCursor hourglass(Cursor_ReallyBusy);
        sem_wait(&m_sema);
    } else {
        //ScopedBusyCursor hourglass( Cursor_KindaBusy );
        while (!WaitWithoutYield(def_yieldgui_interval))
            YieldToMain();
    }
#else
    sem_wait(&m_sema);
#endif
}
Exemple #3
0
// This is a wxApp-safe rendition of AcquireWithoutYield, which makes sure to execute pending app events
// and messages *if* the lock is performed from the main GUI thread.
//
void Threading::Mutex::Acquire()
{
#if wxUSE_GUI
	if( !wxThread::IsMain() || (wxTheApp == NULL) )
	{
		pthread_mutex_lock( &m_mutex );
	}
	else if( _WaitGui_RecursionGuard( L"Mutex::Acquire" ) )
	{
		ScopedBusyCursor hourglass( Cursor_ReallyBusy );
		pthread_mutex_lock( &m_mutex );
	}
	else
	{
		//ScopedBusyCursor hourglass( Cursor_KindaBusy );
		while( !AcquireWithoutYield(def_yieldgui_interval) )
			YieldToMain();
	}
#else
	pthread_mutex_lock( &m_mutex );
#endif
}