Refactor YieldFor() to avoid code duplication among the ports.

Don't repeat the same code in all the ports, move it to the common base class
and add a new virtual DoYieldFor() for the really port-specific code.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76061 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-03-02 18:58:00 +00:00
parent 632c106cd5
commit f740cc3881
19 changed files with 97 additions and 199 deletions

View File

@@ -24,10 +24,10 @@ public:
virtual bool Dispatch();
virtual int DispatchTimeout(unsigned long timeout);
virtual void WakeUp() { }
virtual bool YieldFor(long eventsToProcess);
protected:
virtual int DoRun();
virtual void DoYieldFor(long eventsToProcess);
int m_exitcode;

View File

@@ -153,7 +153,12 @@ public:
// may result in calling the same event handler again), use
// with _extreme_ care or, better, don't use at all!
bool Yield(bool onlyIfNeeded = false);
virtual bool YieldFor(long eventsToProcess) = 0;
// more selective version of Yield()
//
// notice that it is virtual for backwards-compatibility but new code
// should override DoYieldFor() and not YieldFor() itself
virtual bool YieldFor(long eventsToProcess);
// returns true if the main thread is inside a Yield() call
virtual bool IsYielding() const
@@ -182,6 +187,16 @@ protected:
// real implementation of Run()
virtual int DoRun() = 0;
// And the real, port-specific, implementation of YieldFor().
//
// The base class version is pure virtual to ensure that it is overridden
// in the derived classes but does have an implementation which processes
// pending events in wxApp if eventsToProcess allows it, and so should be
// called from the overridden version at an appropriate place (i.e. after
// processing the native events but before doing anything else that could
// be affected by pending events dispatching).
virtual void DoYieldFor(long eventsToProcess) = 0;
// this function should be called before the event loop terminates, whether
// this happens normally (because of Exit() call) or abnormally (because of
// an exception thrown from inside the loop)
@@ -313,10 +328,10 @@ public:
}
}
virtual void WakeUp() { }
virtual bool YieldFor(long eventsToProcess);
protected:
virtual int DoRun();
virtual void DoYieldFor(long eventsToProcess);
// the pointer to the port specific implementation class
wxEventLoopImpl *m_impl;

View File

@@ -26,13 +26,13 @@ public:
virtual bool Dispatch();
virtual int DispatchTimeout(unsigned long timeout);
virtual void WakeUp();
virtual bool YieldFor(long eventsToProcess);
void StoreGdkEventForLaterProcessing(GdkEvent* ev)
{ m_arrGdkEvents.Add(ev); }
protected:
virtual int DoRun();
virtual void DoYieldFor(long eventsToProcess);
private:
// the exit code of this event loop

View File

@@ -54,10 +54,10 @@ public:
virtual bool Dispatch();
virtual int DispatchTimeout(unsigned long timeout);
virtual void WakeUp();
virtual bool YieldFor(long eventsToProcess);
protected:
virtual void OnNextIteration();
virtual void DoYieldFor(long eventsToProcess);
private:
// check if the given window is a child of ms_winCritical (which must be

View File

@@ -40,10 +40,12 @@ public:
virtual bool Dispatch();
virtual int DispatchTimeout(unsigned long timeout);
virtual void WakeUp();
virtual bool YieldFor(long WXUNUSED(eventsToProcess)) { return true; }
// Windows-specific function to process a single message
virtual void ProcessMessage(WXMSG *msg);
protected:
virtual void DoYieldFor(long eventsToProcess);
};
#endif // wxUSE_CONSOLE_EVENTLOOP

View File

@@ -42,8 +42,6 @@ public:
// to it (can be called from non main thread)
virtual void WakeUp();
virtual bool YieldFor(long eventsToProcess);
bool ShouldProcessIdleEvents() const { return m_processIdleEvents ; }
#if wxUSE_UIACTIONSIMULATOR
@@ -57,6 +55,8 @@ protected:
// terminating when Exit() is called
virtual int DoRun();
virtual void DoYieldFor(long eventsToProcess);
void CommonModeObserverCallBack(CFRunLoopObserverRef observer, int activity);
void DefaultModeObserverCallBack(CFRunLoopObserverRef observer, int activity);

View File

@@ -38,10 +38,10 @@ public:
virtual int DispatchTimeout(unsigned long timeout);
virtual void WakeUp();
virtual bool IsOk() const { return m_dispatcher != NULL; }
virtual bool YieldFor(long WXUNUSED(eventsToProcess)) { return true; }
protected:
virtual void OnNextIteration();
virtual void DoYieldFor(long eventsToProcess);
private:
// pipe used for wake up messages: when a child thread wants to wake up