15 #include "threadWin32Impl.h"
16 #include "selectThreadImpl.h"
18 #ifdef THREAD_WIN32_IMPL
21 #include "pointerTo.h"
22 #include "config_pipeline.h"
24 DWORD ThreadWin32Impl::_pt_ptr_index = 0;
25 bool ThreadWin32Impl::_got_pt_ptr_index =
false;
34 if (thread_cat->is_debug()) {
35 thread_cat.debug() <<
"Deleting thread " << _parent_obj->get_name() <<
"\n";
48 void ThreadWin32Impl::
58 bool ThreadWin32Impl::
59 start(ThreadPriority priority,
bool joinable) {
61 if (thread_cat->is_debug()) {
62 thread_cat.debug() <<
"Starting " << *_parent_obj <<
"\n";
65 nassertd(_status == S_new && _thread == 0) {
71 _status = S_start_called;
73 if (!_got_pt_ptr_index) {
81 CreateThread(NULL, 0, &root_func, (
void *)
this, 0, &_thread_id);
83 if (_thread_id == 0) {
87 unref_delete(_parent_obj);
95 SetThreadPriority(_thread, THREAD_PRIORITY_BELOW_NORMAL);
99 SetThreadPriority(_thread, THREAD_PRIORITY_ABOVE_NORMAL);
103 SetThreadPriority(_thread, THREAD_PRIORITY_HIGHEST);
108 SetThreadPriority(_thread, THREAD_PRIORITY_NORMAL);
123 void ThreadWin32Impl::
126 nassertd(_joinable && _status != S_new) {
131 while (_status != S_finished) {
142 string ThreadWin32Impl::
143 get_unique_id()
const {
145 strm << GetCurrentProcessId() <<
"." << _thread_id;
155 DWORD ThreadWin32Impl::
156 root_func(LPVOID data) {
157 TAU_REGISTER_THREAD();
161 ThreadWin32Impl *
self = (ThreadWin32Impl *)data;
162 BOOL result = TlsSetValue(_pt_ptr_index, self->_parent_obj);
166 self->_mutex.acquire();
167 nassertd(self->_status == S_start_called) {
168 self->_mutex.release();
171 self->_status = S_running;
173 self->_mutex.release();
176 self->_parent_obj->thread_main();
178 if (thread_cat->is_debug()) {
180 <<
"Terminating thread " <<
self->_parent_obj->get_name()
181 <<
", count = " <<
self->_parent_obj->get_ref_count() <<
"\n";
185 self->_mutex.acquire();
186 nassertd(self->_status == S_running) {
187 self->_mutex.release();
190 self->_status = S_finished;
192 self->_mutex.release();
198 unref_delete(self->_parent_obj);
210 void ThreadWin32Impl::
211 init_pt_ptr_index() {
212 nassertv(!_got_pt_ptr_index);
214 _pt_ptr_index = TlsAlloc();
215 if (_pt_ptr_index == TLS_OUT_OF_INDEXES) {
217 <<
"Unable to associate Thread pointers with threads.\n";
221 _got_pt_ptr_index =
true;
226 BOOL result = TlsSetValue(_pt_ptr_index, main_thread_obj);
230 #endif // THREAD_WIN32_IMPL
static Thread * get_main_thread()
Returns a pointer to the "main" Thread object–this is the Thread that started the whole process...
A thread; that is, a lightweight process.