Exemplo n.º 1
0
// This is a wxApp-safe implementation of WaitWithoutYield, 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 windows continue to repaint.  If the Wait is
// called from another thread, no message pumping is performed.
//
// Returns:
//   false if the wait timed out before the semaphore was signaled, or true if the signal was
//   reached prior to timeout.
//
bool Threading::Semaphore::Wait(const wxTimeSpan &timeout)
{
#if wxUSE_GUI
    if (!wxThread::IsMain() || (wxTheApp == NULL)) {
        return WaitWithoutYield(timeout);
    } else if (_WaitGui_RecursionGuard(L"Semaphore::TimedWait")) {
        ScopedBusyCursor hourglass(Cursor_ReallyBusy);
        return WaitWithoutYield(timeout);
    } else {
        //ScopedBusyCursor hourglass( Cursor_KindaBusy );
        wxTimeSpan countdown((timeout));

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

        return countdown.GetMilliseconds() > 0;
    }
#else
    return WaitWithoutYield(timeout);
#endif
}
Exemplo n.º 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 windows 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)) {
		WaitWithoutYield();
	}
	else if(_WaitGui_RecursionGuard( L"Semaphore::Wait" )) {
		ScopedBusyCursor hourglass( Cursor_ReallyBusy );
		WaitWithoutYield();
	}
	else {
		while (!WaitWithoutYield(def_yieldgui_interval)) {
			YieldToMain();
		}
	}
#else
	WaitWithoutYield();
#endif
}