Get rid of platform thread_id
This commit is contained in:
parent
8578b8812a
commit
b322011ee2
7 changed files with 17 additions and 83 deletions
|
@ -12,27 +12,6 @@
|
|||
|
||||
class emulator_status;
|
||||
|
||||
/**
|
||||
* Thread ID.
|
||||
*/
|
||||
struct thread_id
|
||||
{
|
||||
/**
|
||||
* Return thread id for this thread. Can be freed with delete.
|
||||
*/
|
||||
static thread_id& me() throw(std::bad_alloc);
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~thread_id() throw();
|
||||
/**
|
||||
* Is this thread me?
|
||||
*/
|
||||
virtual bool is_me() throw() = 0;
|
||||
protected:
|
||||
thread_id() throw();
|
||||
};
|
||||
|
||||
/**
|
||||
* Thread.
|
||||
*/
|
||||
|
|
|
@ -12,10 +12,15 @@ typedef std::condition_variable cv_class;
|
|||
typedef std::mutex mutex_class;
|
||||
typedef std::unique_lock<std::mutex> umutex_class;
|
||||
typedef std::chrono::microseconds microsec_class;
|
||||
typedef std::thread::id threadid_class;
|
||||
inline void cv_timed_wait(cv_class& c, umutex_class& m, const microsec_class& t)
|
||||
{
|
||||
c.wait_for(m, t);
|
||||
}
|
||||
inline threadid_class this_thread_id()
|
||||
{
|
||||
return std::this_thread::get_id();
|
||||
}
|
||||
#else
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/locks.hpp>
|
||||
|
@ -24,10 +29,15 @@ typedef boost::condition_variable cv_class;
|
|||
typedef boost::mutex mutex_class;
|
||||
typedef boost::unique_lock<boost::mutex> umutex_class;
|
||||
typedef boost::posix_time::microseconds microsec_class;
|
||||
typedef boost::thread::id threadid_class;
|
||||
inline void cv_timed_wait(cv_class& c, umutex_class& m, const microsec_class& t)
|
||||
{
|
||||
c.timed_wait(m, t);
|
||||
}
|
||||
inline threadid_class this_thread_id()
|
||||
{
|
||||
return boost::this_thread::get_id();
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
volatile thread_id* threads[DESIGNATED_THREADS];
|
||||
threadid_class threads[DESIGNATED_THREADS];
|
||||
volatile bool thread_marked;
|
||||
mutex_class malloc_mutex;
|
||||
bool initialized = false;
|
||||
|
@ -21,8 +21,8 @@ void assert_thread(signed shouldbe, const std::string& desc)
|
|||
}
|
||||
if(!thread_marked)
|
||||
return;
|
||||
thread_id* t = const_cast<thread_id*>(threads[shouldbe]);
|
||||
if(!t || !t->is_me())
|
||||
threadid_class t = threads[shouldbe];
|
||||
if(t != this_thread_id())
|
||||
std::cerr << "WARNING: " << desc << ": Wrong thread!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ void mark_thread_as(signed call_me)
|
|||
return;
|
||||
}
|
||||
thread_marked = true;
|
||||
threads[call_me] = &thread_id::me();
|
||||
threads[call_me] = this_thread_id();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -29,14 +29,6 @@
|
|||
#define MAXMESSAGES 5000
|
||||
#define INIT_WIN_SIZE 6
|
||||
|
||||
thread_id::thread_id() throw()
|
||||
{
|
||||
}
|
||||
|
||||
thread_id::~thread_id() throw()
|
||||
{
|
||||
}
|
||||
|
||||
thread::thread() throw()
|
||||
{
|
||||
alive = true;
|
||||
|
|
|
@ -1,25 +1,5 @@
|
|||
#include "core/window.hpp"
|
||||
|
||||
struct dummy_thread_id : public thread_id
|
||||
{
|
||||
~dummy_thread_id() throw();
|
||||
bool is_me() throw();
|
||||
};
|
||||
|
||||
dummy_thread_id::~dummy_thread_id() throw()
|
||||
{
|
||||
}
|
||||
|
||||
bool dummy_thread_id::is_me() throw()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
thread_id& thread_id::me() throw(std::bad_alloc)
|
||||
{
|
||||
return *new dummy_thread_id();
|
||||
}
|
||||
|
||||
struct dummy_thread : public thread
|
||||
{
|
||||
dummy_thread();
|
||||
|
|
|
@ -56,7 +56,7 @@ bool wxwidgets_exiting = false;
|
|||
|
||||
namespace
|
||||
{
|
||||
thread_id* ui_thread;
|
||||
threadid_class ui_thread;
|
||||
volatile bool panic_ack = false;
|
||||
std::string modal_dialog_text;
|
||||
volatile bool modal_dialog_confirm;
|
||||
|
@ -442,7 +442,7 @@ bool lsnes_app::OnInit()
|
|||
|
||||
ui_services = new ui_services_type();
|
||||
|
||||
ui_thread = &thread_id::me();
|
||||
ui_thread = this_thread_id();
|
||||
platform::init();
|
||||
|
||||
messages << "lsnes version: lsnes rr" << lsnes_version << std::endl;
|
||||
|
@ -589,7 +589,7 @@ bool graphics_plugin::modal_message(const std::string& text, bool confirm) throw
|
|||
void graphics_plugin::fatal_error() throw()
|
||||
{
|
||||
//Fun: This can be called from any thread!
|
||||
if(ui_thread->is_me()) {
|
||||
if(ui_thread == this_thread_id()) {
|
||||
//UI thread.
|
||||
platform::set_modal_pause(true);
|
||||
wxMessageBox(_T("Panic: Unrecoverable error, can't continue"), _T("Error"), wxICON_ERROR | wxOK);
|
||||
|
|
|
@ -2,33 +2,6 @@
|
|||
|
||||
#include <wx/thread.h>
|
||||
|
||||
struct wxw_thread_id : public thread_id
|
||||
{
|
||||
wxw_thread_id() throw();
|
||||
~wxw_thread_id() throw();
|
||||
bool is_me() throw();
|
||||
uint32_t id;
|
||||
};
|
||||
|
||||
wxw_thread_id::wxw_thread_id() throw()
|
||||
{
|
||||
id = wxThread::GetCurrentId();
|
||||
}
|
||||
|
||||
wxw_thread_id::~wxw_thread_id() throw()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxw_thread_id::is_me() throw()
|
||||
{
|
||||
return (id == wxThread::GetCurrentId());
|
||||
}
|
||||
|
||||
thread_id& thread_id::me() throw(std::bad_alloc)
|
||||
{
|
||||
return *new wxw_thread_id;
|
||||
}
|
||||
|
||||
struct wxw_thread;
|
||||
|
||||
struct wxw_thread_inner : public wxThread
|
||||
|
|
Loading…
Add table
Reference in a new issue