summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-09-22 13:44:32 +0100
committerCarl Hetherington <cth@carlh.net>2012-09-22 13:44:32 +0100
commit21b2cd0a6e34be7590fef11af91fd47985bf970c (patch)
tree18795947d0000a4547544c12785eb4cc3c58e0f1
parent0401db037ade0781849072329feb5eef73d5ca98 (diff)
Be a bit safer with ThreadedStaticText.
-rw-r--r--src/wx/wx_util.cc9
-rw-r--r--src/wx/wx_util.h4
2 files changed, 12 insertions, 1 deletions
diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc
index 5a9986215..712e23570 100644
--- a/src/wx/wx_util.cc
+++ b/src/wx/wx_util.cc
@@ -65,7 +65,14 @@ ThreadedStaticText::ThreadedStaticText (wxWindow* parent, string initial, functi
: wxStaticText (parent, wxID_ANY, std_to_wx (initial))
{
Connect (_update_event_id, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ThreadedStaticText::thread_finished), 0, this);
- thread t (bind (&ThreadedStaticText::run, this, fn));
+ _thread = new thread (bind (&ThreadedStaticText::run, this, fn));
+}
+
+ThreadedStaticText::~ThreadedStaticText ()
+{
+ /* XXX: this is a bit unfortunate */
+ _thread->join ();
+ delete _thread;
}
void
diff --git a/src/wx/wx_util.h b/src/wx/wx_util.h
index 555a3ab0e..3a454c7c4 100644
--- a/src/wx/wx_util.h
+++ b/src/wx/wx_util.h
@@ -19,6 +19,7 @@
#include <wx/wx.h>
#include <boost/function.hpp>
+#include <boost/thread.hpp>
/** @file src/wx/wx_util.h
* @brief Some utility functions and classes.
@@ -36,10 +37,13 @@ class ThreadedStaticText : public wxStaticText
{
public:
ThreadedStaticText (wxWindow* parent, std::string initial, boost::function<std::string ()> fn);
+ ~ThreadedStaticText ();
private:
void run (boost::function<std::string ()> fn);
void thread_finished (wxCommandEvent& ev);
+ boost::thread* _thread;
+
static const int _update_event_id;
};