diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-09-22 13:44:32 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-09-22 13:44:32 +0100 |
| commit | 21b2cd0a6e34be7590fef11af91fd47985bf970c (patch) | |
| tree | 18795947d0000a4547544c12785eb4cc3c58e0f1 | |
| parent | 0401db037ade0781849072329feb5eef73d5ca98 (diff) | |
Be a bit safer with ThreadedStaticText.
| -rw-r--r-- | src/wx/wx_util.cc | 9 | ||||
| -rw-r--r-- | src/wx/wx_util.h | 4 |
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; }; |
