Added wxThread::OnKill() and OnDelete() callbacks.
Call OnXXX() from wxThread::Kill() and Delete() respectively to allow the thread being terminated perform some cleanup. Closes #9046. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65882 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
ec2c85bf79
commit
df191bfe39
@ -406,6 +406,7 @@ Major new features in this release
|
|||||||
All:
|
All:
|
||||||
|
|
||||||
- Added "rest" argument to wxString::Before{First,Last}().
|
- Added "rest" argument to wxString::Before{First,Last}().
|
||||||
|
- Added wxThread::OnKill() and OnDelete() callbacks.
|
||||||
|
|
||||||
All (GUI):
|
All (GUI):
|
||||||
|
|
||||||
|
@ -585,6 +585,19 @@ protected:
|
|||||||
// of this thread.
|
// of this thread.
|
||||||
virtual void *Entry() = 0;
|
virtual void *Entry() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Callbacks which may be overridden by the derived class to perform some
|
||||||
|
// specific actions when the thread is deleted or killed. By default they
|
||||||
|
// do nothing.
|
||||||
|
|
||||||
|
// This one is called by Delete() before actually deleting the thread and
|
||||||
|
// is executed in the context of the thread that called Delete().
|
||||||
|
virtual void OnDelete() {}
|
||||||
|
|
||||||
|
// This one is called by Kill() before killing the thread and is executed
|
||||||
|
// in the context of the thread that called Kill().
|
||||||
|
virtual void OnKill() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// no copy ctor/assignment operator
|
// no copy ctor/assignment operator
|
||||||
wxThread(const wxThread&);
|
wxThread(const wxThread&);
|
||||||
|
@ -454,6 +454,37 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual ExitCode Entry() = 0;
|
virtual ExitCode Entry() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback called by Delete() before actually deleting the thread.
|
||||||
|
|
||||||
|
This function can be overridden by the derived class to perform some
|
||||||
|
specific task when the thread is gracefully destroyed. Notice that it
|
||||||
|
will be executed in the context of the thread that called Delete() and
|
||||||
|
<b>not</b> in this thread's context.
|
||||||
|
|
||||||
|
TestDestroy() will be true for the thread before OnDelete() gets
|
||||||
|
executed.
|
||||||
|
|
||||||
|
@since 2.9.2
|
||||||
|
|
||||||
|
@see OnKill()
|
||||||
|
*/
|
||||||
|
virtual void OnDelete();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Callback called by Kill() before actually killing the thread.
|
||||||
|
|
||||||
|
This function can be overridden by the derived class to perform some
|
||||||
|
specific task when the thread is terminated. Notice that it will be
|
||||||
|
executed in the context of the thread that called Kill() and <b>not</b>
|
||||||
|
in this thread's context.
|
||||||
|
|
||||||
|
@since 2.9.2
|
||||||
|
|
||||||
|
@see OnDelete()
|
||||||
|
*/
|
||||||
|
virtual void OnKill();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@deprecated
|
@deprecated
|
||||||
Use CreateThread() instead.
|
Use CreateThread() instead.
|
||||||
|
@ -686,6 +686,8 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize)
|
|||||||
|
|
||||||
wxThreadError wxThreadInternal::Kill()
|
wxThreadError wxThreadInternal::Kill()
|
||||||
{
|
{
|
||||||
|
m_thread->OnKill();
|
||||||
|
|
||||||
if ( !::TerminateThread(m_hThread, THREAD_ERROR_EXIT) )
|
if ( !::TerminateThread(m_hThread, THREAD_ERROR_EXIT) )
|
||||||
{
|
{
|
||||||
wxLogSysError(_("Couldn't terminate thread"));
|
wxLogSysError(_("Couldn't terminate thread"));
|
||||||
@ -759,6 +761,7 @@ wxThreadInternal::WaitForTerminate(wxCriticalSection& cs,
|
|||||||
Cancel();
|
Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
threadToDelete->OnDelete();
|
||||||
|
|
||||||
// now wait for thread to finish
|
// now wait for thread to finish
|
||||||
if ( wxThread::IsMain() )
|
if ( wxThread::IsMain() )
|
||||||
|
@ -1453,6 +1453,8 @@ wxThreadError wxThread::Delete(ExitCode *rc)
|
|||||||
|
|
||||||
m_critsect.Leave();
|
m_critsect.Leave();
|
||||||
|
|
||||||
|
OnDelete();
|
||||||
|
|
||||||
switch ( state )
|
switch ( state )
|
||||||
{
|
{
|
||||||
case STATE_NEW:
|
case STATE_NEW:
|
||||||
@ -1501,6 +1503,8 @@ wxThreadError wxThread::Kill()
|
|||||||
wxCHECK_MSG( This() != this, wxTHREAD_MISC_ERROR,
|
wxCHECK_MSG( This() != this, wxTHREAD_MISC_ERROR,
|
||||||
wxT("a thread can't kill itself") );
|
wxT("a thread can't kill itself") );
|
||||||
|
|
||||||
|
OnKill();
|
||||||
|
|
||||||
switch ( m_internal->GetState() )
|
switch ( m_internal->GetState() )
|
||||||
{
|
{
|
||||||
case STATE_NEW:
|
case STATE_NEW:
|
||||||
|
Loading…
Reference in New Issue
Block a user