1 #include "core/window.hpp"
5 struct wxw_mutex
: public mutex
7 wxw_mutex() throw(std::bad_alloc
);
10 void unlock() throw();
14 wxw_mutex::wxw_mutex() throw(std::bad_alloc
)
19 wxw_mutex::~wxw_mutex() throw()
24 void wxw_mutex::lock() throw()
29 void wxw_mutex::unlock() throw()
34 mutex
& mutex::aquire() throw(std::bad_alloc
)
36 return *new wxw_mutex
;
39 struct wxw_condition
: public condition
41 wxw_condition(mutex
& m
) throw(std::bad_alloc
);
42 ~wxw_condition() throw();
43 bool wait(uint64_t x
) throw();
44 void signal() throw();
48 wxw_condition::wxw_condition(mutex
& m
) throw(std::bad_alloc
)
51 wxw_mutex
* m2
= dynamic_cast<wxw_mutex
*>(&m
);
52 c
= new wxCondition(*m2
->m
);
55 wxw_condition::~wxw_condition() throw()
60 bool wxw_condition::wait(uint64_t x
) throw()
62 wxCondError e
= c
->WaitTimeout((x
+ 999) / 1000);
63 return (e
== wxCOND_NO_ERROR
);
66 void wxw_condition::signal() throw()
71 condition
& condition::aquire(mutex
& m
) throw(std::bad_alloc
)
73 return *new wxw_condition(m
);
76 struct wxw_thread_id
: public thread_id
78 wxw_thread_id() throw();
79 ~wxw_thread_id() throw();
84 wxw_thread_id::wxw_thread_id() throw()
86 id
= wxThread::GetCurrentId();
89 wxw_thread_id::~wxw_thread_id() throw()
93 bool wxw_thread_id::is_me() throw()
95 return (id
== wxThread::GetCurrentId());
98 thread_id
& thread_id::me() throw(std::bad_alloc
)
100 return *new wxw_thread_id
;
105 struct wxw_thread_inner
: public wxThread
107 wxw_thread_inner(wxw_thread
* _up
);
108 void* (*entry
)(void* arg
);
110 wxThread::ExitCode
Entry();
114 struct wxw_thread
: public thread
116 wxw_thread(void* (*fn
)(void* arg
), void* arg
) throw(std::bad_alloc
, std::runtime_error
);
117 ~wxw_thread() throw();
118 void _join() throw();
120 wxw_thread_inner
* inner
;
121 void notify_quit2(void* ret
);
124 wxw_thread_inner::wxw_thread_inner(wxw_thread
* _up
)
125 : wxThread(wxTHREAD_JOINABLE
)
130 void wxw_thread::notify_quit2(void* ret
)
135 wxThread::ExitCode
wxw_thread_inner::Entry()
137 up
->notify_quit2(entry(entry_arg
));
141 wxw_thread::wxw_thread(void* (*fn
)(void* arg
), void* arg
) throw(std::bad_alloc
, std::runtime_error
)
144 inner
= new wxw_thread_inner(this);
146 inner
->entry_arg
= arg
;
147 wxThreadError e
= inner
->Create(8 * 1024 * 1024);
148 if(e
!= wxTHREAD_NO_ERROR
)
149 throw std::bad_alloc();
151 if(e
!= wxTHREAD_NO_ERROR
)
152 throw std::bad_alloc();
155 wxw_thread::~wxw_thread() throw()
163 void wxw_thread::_join() throw()
171 thread
& thread::create(void* (*entrypoint
)(void* arg
), void* arg
) throw(std::bad_alloc
, std::runtime_error
)
173 return *new wxw_thread(entrypoint
, arg
);