17#ifdef THREAD_WIN32_IMPL
23DWORD ThreadWin32Impl::_pt_ptr_index = 0;
24bool ThreadWin32Impl::_got_pt_ptr_index =
false;
31 if (thread_cat->is_debug()) {
32 thread_cat.debug() <<
"Deleting thread " << _parent_obj->get_name() <<
"\n";
51start(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);
111void ThreadWin32Impl::
114 nassertd(_joinable && _status != S_new) {
119 while (_status != S_finished) {
128std::string ThreadWin32Impl::
129get_unique_id()
const {
130 std::ostringstream strm;
131 strm << GetCurrentProcessId() <<
"." << _thread_id;
139DWORD ThreadWin32Impl::
140root_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();
192void ThreadWin32Impl::
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.