17 #ifdef THREAD_WIN32_IMPL
23 DWORD ThreadWin32Impl::_pt_ptr_index = 0;
24 bool ThreadWin32Impl::_got_pt_ptr_index =
false;
31 if (thread_cat->is_debug()) {
32 thread_cat.debug() <<
"Deleting thread " << _parent_obj->get_name() <<
"\n";
42 void ThreadWin32Impl::
50 bool ThreadWin32Impl::
51 start(ThreadPriority priority,
bool joinable) {
53 if (thread_cat->is_debug()) {
54 thread_cat.debug() <<
"Starting " << *_parent_obj <<
"\n";
57 nassertd(_status == S_new && _thread == 0) {
63 _status = S_start_called;
65 if (!_got_pt_ptr_index) {
73 CreateThread(
nullptr, 0, &root_func, (
void *)
this, 0, &_thread_id);
75 if (_thread_id == 0) {
86 SetThreadPriority(_thread, THREAD_PRIORITY_BELOW_NORMAL);
90 SetThreadPriority(_thread, THREAD_PRIORITY_ABOVE_NORMAL);
94 SetThreadPriority(_thread, THREAD_PRIORITY_HIGHEST);
99 SetThreadPriority(_thread, THREAD_PRIORITY_NORMAL);
111 void ThreadWin32Impl::
114 nassertd(_joinable && _status != S_new) {
119 while (_status != S_finished) {
128 std::string ThreadWin32Impl::
129 get_unique_id()
const {
130 std::ostringstream strm;
131 strm << GetCurrentProcessId() <<
"." << _thread_id;
139 DWORD ThreadWin32Impl::
140 root_func(LPVOID data) {
141 TAU_REGISTER_THREAD();
145 ThreadWin32Impl *
self = (ThreadWin32Impl *)data;
146 BOOL result = TlsSetValue(_pt_ptr_index, self->_parent_obj);
151 nassertd(self->_status == S_start_called) {
152 self->_mutex.unlock();
155 self->_status = S_running;
157 self->_mutex.unlock();
160 self->_parent_obj->thread_main();
162 if (thread_cat->is_debug()) {
164 <<
"Terminating thread " <<
self->_parent_obj->get_name()
165 <<
", count = " <<
self->_parent_obj->get_ref_count() <<
"\n";
170 nassertd(self->_status == S_running) {
171 self->_mutex.unlock();
174 self->_status = S_finished;
176 self->_mutex.unlock();
192 void ThreadWin32Impl::
193 init_pt_ptr_index() {
194 nassertv(!_got_pt_ptr_index);
196 _pt_ptr_index = TlsAlloc();
197 if (_pt_ptr_index == TLS_OUT_OF_INDEXES) {
199 <<
"Unable to associate Thread pointers with threads.\n";
203 _got_pt_ptr_index =
true;
208 BOOL result = TlsSetValue(_pt_ptr_index, main_thread_obj);
A thread; that is, a lightweight process.
get_main_thread
Returns a pointer to the "main" Thread object–this is the Thread that started the whole process.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void unref_delete(RefCountType *ptr)
This global helper function will unref the given ReferenceCount object, and if the reference count re...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.