add a wxEventType argument to wxThreadEvent for coherency with other event classes; rewrite its Clone() function
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58661 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1073,17 +1073,18 @@ private:
|
|||||||
class WXDLLIMPEXP_CORE wxThreadEvent : public wxCommandEvent
|
class WXDLLIMPEXP_CORE wxThreadEvent : public wxCommandEvent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxThreadEvent(int id = wxID_ANY)
|
wxThreadEvent(wxEventType eventType = wxEVT_COMMAND_THREAD, int id = wxID_ANY)
|
||||||
: wxCommandEvent(wxEVT_COMMAND_THREAD, id)
|
: wxCommandEvent(eventType, id)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual wxEvent *Clone() const
|
virtual wxEvent *Clone() const
|
||||||
{
|
{
|
||||||
// make sure our string member (which uses COW aka refcounting) is not
|
wxThreadEvent* ev = new wxThreadEvent(*this);
|
||||||
// shared by other string instances:
|
|
||||||
const_cast<wxThreadEvent*>(this)->SetString(GetString().c_str());
|
|
||||||
|
|
||||||
return new wxThreadEvent(*this);
|
// make sure our string member (which uses COW, aka refcounting) is not
|
||||||
|
// shared by other wxString instances:
|
||||||
|
ev->SetString(GetString().c_str());
|
||||||
|
return ev;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is important to avoid that calling wxApp::Yield() thread events
|
// this is important to avoid that calling wxApp::Yield() thread events
|
||||||
|
@@ -2544,11 +2544,8 @@ class wxThreadEvent : public wxCommandEvent
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
Constructor.
|
Constructor.
|
||||||
|
|
||||||
Initializes the event type to @c wxEVT_THREAD (but you can change it
|
|
||||||
using wxEvent::SetEventType.
|
|
||||||
*/
|
*/
|
||||||
wxThreadEvent(int id = wxID_ANY);
|
wxThreadEvent(wxEventType eventType = wxEVT_COMMAND_THREAD, int id = wxID_ANY);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Clones this event making sure that all internal members which use
|
Clones this event making sure that all internal members which use
|
||||||
@@ -2560,8 +2557,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
Returns @c wxEVT_CATEGORY_THREAD.
|
Returns @c wxEVT_CATEGORY_THREAD.
|
||||||
|
|
||||||
This is important to avoid that calling wxApp::Yield() thread events
|
This is important to avoid unwanted processing of thread events
|
||||||
gets processed when this is unwanted:
|
when calling wxApp::YieldFor().
|
||||||
*/
|
*/
|
||||||
virtual wxEventCategory GetEventCategory() const;
|
virtual wxEventCategory GetEventCategory() const;
|
||||||
};
|
};
|
||||||
|
@@ -292,7 +292,7 @@ void MyWorkerThread::OnExit()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_YIELD_RACE_CONDITION 1
|
#define TEST_YIELD_RACE_CONDITION 0
|
||||||
|
|
||||||
void *MyWorkerThread::Entry()
|
void *MyWorkerThread::Entry()
|
||||||
{
|
{
|
||||||
@@ -300,7 +300,7 @@ void *MyWorkerThread::Entry()
|
|||||||
if ( TestDestroy() )
|
if ( TestDestroy() )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
wxThreadEvent event( WORKER_EVENT );
|
wxThreadEvent event( wxEVT_COMMAND_THREAD, WORKER_EVENT );
|
||||||
|
|
||||||
event.SetInt( 50 );
|
event.SetInt( 50 );
|
||||||
wxQueueEvent( m_frame, new wxThreadEvent(event) );
|
wxQueueEvent( m_frame, new wxThreadEvent(event) );
|
||||||
@@ -315,7 +315,7 @@ void *MyWorkerThread::Entry()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
// create any type of command event here
|
// create any type of command event here
|
||||||
wxThreadEvent event( WORKER_EVENT );
|
wxThreadEvent event( wxEVT_COMMAND_THREAD, WORKER_EVENT );
|
||||||
event.SetInt( m_count );
|
event.SetInt( m_count );
|
||||||
|
|
||||||
// send in a thread-safe way
|
// send in a thread-safe way
|
||||||
@@ -324,7 +324,7 @@ void *MyWorkerThread::Entry()
|
|||||||
wxMilliSleep(200);
|
wxMilliSleep(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxThreadEvent event( WORKER_EVENT );
|
wxThreadEvent event( wxEVT_COMMAND_THREAD, WORKER_EVENT );
|
||||||
event.SetInt(-1); // that's all
|
event.SetInt(-1); // that's all
|
||||||
wxQueueEvent( m_frame, new wxThreadEvent(event) );
|
wxQueueEvent( m_frame, new wxThreadEvent(event) );
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user