Panda3D
|
A thread; that is, a lightweight process. More...
#include "thread.h"
Classes | |
class | PStatsCallback |
Public Member Functions | |
virtual TypeHandle | force_init_type () |
AsyncTaskBase * | get_current_task () const |
Returns the task currently executing on this thread (via the AsyncTaskManager), if any, or NULL if the thread is not currently servicing a task. More... | |
int | get_pipeline_stage () const |
Returns the Pipeline stage number associated with this thread. More... | |
PStatsCallback * | get_pstats_callback () const |
Returns the PStats callback associated with this thread, or NULL if no callback has yet been associated with this thread. More... | |
int | get_pstats_index () const |
Returns the PStats index associated with this thread, or -1 if no index has yet been associated with this thread. More... | |
const string & | get_sync_name () const |
Returns the sync name of the thread. More... | |
virtual TypeHandle | get_type () const |
string | get_unique_id () const |
Returns a string that is guaranteed to be unique to this thread, across all processes on the machine, during at least the lifetime of this process. More... | |
bool | is_joinable () const |
Returns the value of joinable that was passed to the start() call. More... | |
bool | is_started () const |
Returns true if the thread has been started, false if it has not, or if join() has already been called. More... | |
void | join () |
Blocks the calling process until the thread terminates. More... | |
virtual void | output (ostream &out) const |
void | output_blocker (ostream &out) const |
Writes a description of the mutex or condition variable that this thread is blocked on. More... | |
void | preempt () |
Indicates that this thread should run as soon as possible, preemptying any other threads that may be scheduled to run. More... | |
void | set_min_pipeline_stage (int min_pipeline_stage) |
Sets this thread's pipeline stage number to at least the indicated value, unless it is already larger. More... | |
void | set_pipeline_stage (int pipeline_stage) |
Specifies the Pipeline stage number associated with this thread. More... | |
void | set_pstats_callback (PStatsCallback *pstats_callback) |
Stores a PStats callback to be associated with this thread. More... | |
void | set_pstats_index (int pstats_index) |
Stores a PStats index to be associated with this thread. More... | |
bool | start (ThreadPriority priority, bool joinable) |
Starts the thread executing. More... | |
![]() | |
TypedReferenceCount (const TypedReferenceCount ©) | |
void | operator= (const TypedReferenceCount ©) |
![]() | |
TypedObject (const TypedObject ©) | |
TypedObject * | as_typed_object () |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
const TypedObject * | as_typed_object () const |
Returns the object, upcast (if necessary) to a TypedObject pointer. More... | |
int | get_best_parent_from_Set (const std::set< int > &) const |
int | get_type_index () const |
Returns the internal index number associated with this object's TypeHandle, a unique number for each different type. More... | |
bool | is_exact_type (TypeHandle handle) const |
Returns true if the current object is the indicated type exactly. More... | |
bool | is_of_type (TypeHandle handle) const |
Returns true if the current object is or derives from the indicated type. More... | |
void | operator= (const TypedObject ©) |
![]() | |
int | get_ref_count () const |
Returns the current reference count. More... | |
WeakReferenceList * | get_weak_list () const |
Returns the WeakReferenceList associated with this ReferenceCount object. More... | |
bool | has_weak_list () const |
Returns true if this particular ReferenceCount object has a WeakReferenceList created, false otherwise. More... | |
void | local_object () |
This function should be called, once, immediately after creating a new instance of some ReferenceCount-derived object on the stack. More... | |
void | ref () const |
Explicitly increments the reference count. More... | |
bool | test_ref_count_integrity () const |
Does some easy checks to make sure that the reference count isn't completely bogus. More... | |
bool | test_ref_count_nonzero () const |
Does some easy checks to make sure that the reference count isn't zero, or completely bogus. More... | |
virtual bool | unref () const |
Explicitly decrements the reference count. More... | |
void | weak_ref (WeakPointerToVoid *ptv) |
Adds the indicated PointerToVoid as a weak reference to this object. More... | |
void | weak_unref (WeakPointerToVoid *ptv) |
Removes the indicated PointerToVoid as a weak reference to this object. More... | |
![]() | |
Namable (const string &initial_name="") | |
Namable (const Namable ©) | |
void | clear_name () |
Resets the Namable's name to empty. More... | |
const string & | get_name () const |
bool | has_name () const |
Returns true if the Namable has a nonempty name set, false if the name is empty. More... | |
Namable & | operator= (const Namable &other) |
void | output (ostream &out) const |
Outputs the Namable. More... | |
void | set_name (const string &name) |
Static Public Member Functions | |
static void | consider_yield () |
Possibly suspends the current thread for the rest of the current epoch, if it has run for enough this epoch. More... | |
static void | force_yield () |
Suspends the current thread for the rest of the current epoch. More... | |
static TypeHandle | get_class_type () |
static int | get_current_pipeline_stage () |
Returns the integer pipeline stage associated with the current thread. More... | |
static Thread * | get_current_thread () |
Returns a pointer to the currently-executing Thread object. More... | |
static Thread * | get_external_thread () |
Returns a pointer to the "external" Thread object–this is a special Thread object that corresponds to any thread spawned outside of Panda's threading interface. More... | |
static Thread * | get_main_thread () |
Returns a pointer to the "main" Thread object–this is the Thread that started the whole process. More... | |
static void | init_type () |
static bool | is_simple_threads () |
Returns true if Panda is currently compiled for "simple threads", which is to say, cooperative context switching only, reducing the need for quite so many critical section protections. More... | |
static bool | is_threading_supported () |
Returns true if threading support has been compiled in and enabled, or false if no threading is available (and Thread::start() will always fail). More... | |
static bool | is_true_threads () |
Returns true if a real threading library is available that supports actual OS-implemented threads, or false if the only threading we can provide is simulated user-space threading. More... | |
static void | prepare_for_exit () |
Should be called by the main thread just before exiting the program, this blocks until any remaining thread cleanup has finished. More... | |
static | PT (Thread) bind_thread(const string &name |
static void | sleep (double seconds) |
Suspends the current thread for at least the indicated amount of time. More... | |
static void | write_status (ostream &out) |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
This function is declared non-inline to work around a compiler bug in g++ 2.96. More... | |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
![]() | |
static TypeHandle | get_class_type () |
static void | init_type () |
Public Attributes | |
static const string & | sync_name |
A thread; that is, a lightweight process.
This is an abstract base class; to use it, you must subclass from it and redefine thread_main().
The thread itself will keep a reference count on the Thread object while it is running; when the thread returns from its root function, the Thread object will automatically be destructed if no other pointers are referencing it.
|
inlinestatic |
Possibly suspends the current thread for the rest of the current epoch, if it has run for enough this epoch.
This is especially important for the simple thread implementation, which relies on cooperative yields like this.
Definition at line 263 of file thread.I.
References is_started().
Referenced by PartGroup::check_hierarchy(), SceneGraphReducer::check_live_flatten(), PartGroup::determine_effective_channels(), Texture::ensure_loader_type(), VertexDataPage::flush_threads(), force_yield(), DatagramInputFile::get_datagram(), Texture::get_ram_image_as(), EggLoader::make_polyset(), EggMesher::mesh(), PNMImage::quick_filter_from(), PNMReader::read_data(), VertexDataSaveFile::read_data(), DatagramInputFile::read_header(), BamReader::read_pointer(), SceneGraphReducer::remove_unused_vertices(), GraphicsEngine::render_frame(), FfmpegVideoCursor::set_time(), ConnectionWriter::shutdown(), ConnectionReader::shutdown(), and PNMWriter::write_data().
|
inlinestatic |
Suspends the current thread for the rest of the current epoch.
Definition at line 248 of file thread.I.
References consider_yield().
Referenced by DatagramGeneratorNet::get_datagram(), MayaToEggServer::poll(), VertexDataSaveFile::read_data(), GraphicsEngine::render_frame(), ConnectionReader::shutdown(), sleep(), and ConnectionManager::wait_for_readers().
|
inlinestatic |
Returns the integer pipeline stage associated with the current thread.
This is the same thing as get_current_thread()->get_pipeline_stage(), but it may be faster to retrieve in some contexts.
Definition at line 167 of file thread.I.
References get_current_thread(), get_pipeline_stage(), and is_threading_supported().
Referenced by PartBundle::clear_control_effects(), DisplayRegion::compute_pixels_all_stages(), PartBundle::control_activated(), PartBundle::do_bind_anim(), get_current_thread(), DisplayRegion::set_active(), PartBundle::set_anim_blend_flag(), PartBundle::set_blend_type(), DisplayRegion::set_camera(), PartBundle::set_control_effect(), DisplayRegion::set_dimensions(), PartBundle::set_frame_blend_flag(), DisplayRegion::set_lens_index(), PartBundle::set_root_xform(), DisplayRegion::set_sort(), DisplayRegion::set_stereo_channel(), DisplayRegion::set_target_tex_page(), DisplayRegion::set_tex_view_offset(), and PartBundle::xform().
|
inline |
Returns the task currently executing on this thread (via the AsyncTaskManager), if any, or NULL if the thread is not currently servicing a task.
Definition at line 329 of file thread.I.
References prepare_for_exit().
Referenced by preempt().
|
inlinestatic |
Returns a pointer to the currently-executing Thread object.
If this is called from the main thread, this will return the same value as get_main_thread().
This will always return some valid Thread pointer. It will never return NULL, even if the current thread was spawned outside of Panda's threading system, although all non-Panda threads will return the exact same Thread pointer.
Definition at line 145 of file thread.I.
References get_current_pipeline_stage(), get_external_thread(), and get_main_thread().
Referenced by GeomNode::add_geom(), GeomNode::add_geoms_from(), SpeedTreeNode::add_instances(), CharacterJoint::add_local_transform(), CharacterJoint::add_net_transform(), Geom::add_primitive(), TransformBlend::add_transform(), PandaNode::adjust_draw_mask(), GeomNode::apply_attribs_to_vertices(), PartBundleNode::apply_attribs_to_vertices(), PandaNode::apply_attribs_to_vertices(), Geom::check_valid(), GeomPrimitive::check_valid(), PandaNode::clear_attrib(), CollisionTraverser::clear_colliders(), PandaNode::clear_effect(), Geom::clear_primitives(), GeomVertexData::clear_rows(), GeomVertexArrayData::compare_to(), JointVertexTransform::complete_pointers(), TransformTable::complete_pointers(), SliderTable::complete_pointers(), TransformBlendTable::complete_pointers(), PandaNode::copy_all_properties(), GeomVertexData::copy_row_from(), PandaNode::copy_tags(), GraphicsStateGuardian::create_gamma_table(), VideoTexture::cull_callback(), RigidBodyCombiner::cull_callback(), GeomNode::decompose(), Geom::decompose_in_place(), GraphicsEngine::do_cull(), GeomNode::do_premunge(), MayaPview::doIt(), Geom::doubleside_in_place(), Texture::ensure_loader_type(), GeomNode::finalize(), PartBundle::finalize(), GeomTransformer::finish_collect(), MultitexReducer::flatten(), GraphicsEngine::flip_frame(), DriveInterface::force_dgraph(), PartBundle::force_update(), get_current_pipeline_stage(), CycleDataStageReader< CycleDataType >::get_current_thread(), CycleDataLockedStageReader< CycleDataType >::get_current_thread(), CycleDataReader< CycleDataType >::get_current_thread(), CycleDataStageWriter< CycleDataType >::get_current_thread(), CycleDataWriter< CycleDataType >::get_current_thread(), CycleDataLockedReader< CycleDataType >::get_current_thread(), get_external_thread(), GeomPrimitive::get_first_vertex(), DXGraphicsStateGuardian9::get_index_type(), GeomPrimitive::get_max_vertex(), GeomPrimitive::get_min_vertex(), ReMutexDirect::get_name(), PandaNode::get_net_collide_mask(), PandaNode::get_net_draw_control_mask(), PandaNode::get_net_draw_show_mask(), AsyncTaskChain::get_next_wake_time(), WorkingNodePath::get_node(), GeomVertexData::get_num_arrays(), GeomVertexData::get_num_bytes(), WorkingNodePath::get_num_nodes(), GeomPrimitive::get_num_primitives(), GeomVertexData::get_num_rows(), GeomPrimitive::get_num_vertices(), DisplayRegion::get_screenshot(), PStatThread::get_thread(), Geom::get_usage_hint(), GeomPrimitive::get_vertex(), TransformBlend::get_weight(), RenderAttrib::init_attribs(), RenderEffects::init_states(), RenderState::init_states(), PandaNode::is_ambient_light(), GeomPrimitive::is_indexed(), TextAssembler::is_whitespace(), JointVertexTransform::JointVertexTransform(), PandaFramework::main_loop(), Geom::make_lines_in_place(), Geom::make_nonindexed(), GeomPrimitive::make_nonindexed(), Geom::make_patches_in_place(), Geom::make_points_in_place(), TransformBlend::normalize_weights(), Geom::offset_vertices(), GraphicsEngine::open_windows(), ReMutexDirect::output(), NodePathComponent::output(), GeomPrimitive::pack_vertices(), DXGraphicsStateGuardian9::prepare_vertex_buffer(), PandaNode::r_prepare_scene(), BamReader::read_cdata(), VertexDataSaveFile::read_data(), GraphicsEngine::ready_flip(), ProjectionScreen::recompute_if_stale(), BamReader::register_pta(), GeomTransformer::register_vertices(), GraphicsEngine::remove_all_windows(), Geom::remove_primitive(), TransformBlend::remove_transform(), GraphicsEngine::remove_window(), GraphicsEngine::render_frame(), PandaNode::replace_node(), GeomVertexData::reserve_num_rows(), SheetNode::reset_bound(), RopeNode::reset_bound(), Geom::reverse_in_place(), Geom::rotate_in_place(), GeomVertexData::set_array(), PandaNode::set_attrib(), PandaNode::set_bounds(), PandaNode::set_bounds_type(), ClockObject::set_dt(), PandaNode::set_effect(), GeomVertexData::set_format(), ClockObject::set_frame_rate(), PandaNode::set_into_collide_mask(), UserVertexTransform::set_matrix(), ClockObject::set_mode(), GeomVertexData::set_num_rows(), Geom::set_primitive(), AsyncTask::set_priority(), CullTraverser::set_scene(), UserVertexSlider::set_slider(), FrameRateMeter::set_text_pattern(), GeomVertexData::set_transform_table(), Geom::set_usage_hint(), Geom::set_vertex_data(), ConnectionReader::shutdown(), BamCache::store(), GraphicsEngine::sync_frame(), GeomTransformer::transform_vertices(), GeomVertexData::unclean_set_format(), GeomVertexData::unclean_set_num_rows(), GeomNode::unify(), Geom::unify_in_place(), DisplayRegionDrawCallbackData::upcall(), DisplayRegionCullCallbackData::upcall(), GeomDrawCallbackData::upcall(), CallbackGraphicsWindow::RenderCallbackData::upcall(), SceneGraphAnalyzerMeter::update(), FrameRateMeter::update(), PartBundle::update(), LODNode::verify_child_bounds(), AnimControl::wait_pending(), and BamWriter::write_cdata().
|
inlinestatic |
Returns a pointer to the "external" Thread object–this is a special Thread object that corresponds to any thread spawned outside of Panda's threading interface.
Note that multiple different threads may share this same pointer.
Definition at line 124 of file thread.I.
References get_current_thread().
Referenced by get_current_thread(), and get_main_thread().
|
inlinestatic |
Returns a pointer to the "main" Thread object–this is the Thread that started the whole process.
Definition at line 107 of file thread.I.
References get_external_thread().
Referenced by get_current_thread(), RenderAttrib::init_attribs(), RenderEffects::init_states(), RenderState::init_states(), set_min_pipeline_stage(), and start().
|
inline |
Returns the Pipeline stage number associated with this thread.
The default stage is 0 if no stage is specified otherwise. See set_pipeline_stage().
Definition at line 84 of file thread.I.
References set_min_pipeline_stage().
Referenced by PandaNode::add_stashed(), NodePath::any_path(), NodePath::attach_new_node(), PandaNode::clear_bounds(), NodePath::detach_node(), NodePath::get_ancestor(), NodePath::get_child(), NodePath::get_children(), get_current_pipeline_stage(), NodePath::get_hidden_ancestor(), PandaNode::get_net_collide_mask(), PandaNode::get_net_draw_control_mask(), PandaNode::get_net_draw_show_mask(), WorkingNodePath::get_node(), NodePath::get_node(), WorkingNodePath::get_num_nodes(), NodePath::get_num_nodes(), NodePath::get_parent(), NodePath::get_sort(), NodePath::get_stashed_ancestor(), NodePath::get_stashed_children(), NodePath::get_top(), get_unique_id(), NodePath::instance_to(), NodePath::is_singleton(), NodePath::NodePath(), NodePathComponent::output(), PandaNode::remove_child(), NodePath::remove_node(), PandaNode::remove_stashed(), NodePath::reparent_to(), PandaNode::reset_all_prev_transform(), SheetNode::reset_bound(), RopeNode::reset_bound(), PandaNode::set_bound(), ClockObject::set_frame_count(), ClockObject::set_frame_rate(), ClockObject::set_frame_time(), ClockObject::set_mode(), NodePath::stash(), PandaNode::stash_child(), NodePath::stash_to(), ClockObject::tick(), NodePath::unstash(), PandaNode::unstash_child(), and NodePath::verify_complete().
|
inline |
Returns the PStats callback associated with this thread, or NULL if no callback has yet been associated with this thread.
This is used internally by the PStatClient; you should not need to call this directly.
Definition at line 379 of file thread.I.
Referenced by set_pstats_callback().
|
inline |
Returns the PStats index associated with this thread, or -1 if no index has yet been associated with this thread.
This is used internally by the PStatClient; you should not need to call this directly.
Definition at line 60 of file thread.I.
References get_unique_id().
Referenced by get_sync_name(), and PStatThread::PStatThread().
|
inline |
Returns the sync name of the thread.
This name collects threads into "sync groups", which are expected to run synchronously. This is mainly used for the benefit of PStats; threads with the same sync name can be ticked all at once via the thread_tick() call.
Definition at line 47 of file thread.I.
References get_pstats_index().
|
inline |
Returns a string that is guaranteed to be unique to this thread, across all processes on the machine, during at least the lifetime of this process.
Definition at line 72 of file thread.I.
References get_pipeline_stage().
Referenced by get_pstats_index(), and BamCache::store().
|
inline |
Returns the value of joinable that was passed to the start() call.
Definition at line 286 of file thread.I.
References join().
Referenced by is_started().
|
inlinestatic |
Returns true if Panda is currently compiled for "simple threads", which is to say, cooperative context switching only, reducing the need for quite so many critical section protections.
This is not necessarily the opposite of "true threads", since one possible implementation of simple threads is via true threads with mutex protection to ensure only one runs at a time.
Definition at line 221 of file thread.I.
References sleep().
Referenced by is_true_threads().
|
inline |
Returns true if the thread has been started, false if it has not, or if join() has already been called.
Definition at line 275 of file thread.I.
References is_joinable().
Referenced by consider_yield().
|
inlinestatic |
Returns true if threading support has been compiled in and enabled, or false if no threading is available (and Thread::start() will always fail).
Definition at line 185 of file thread.I.
References is_true_threads().
Referenced by ConnectionReader::ConnectionReader(), ConnectionWriter::ConnectionWriter(), VertexDataPage::flush_threads(), get_current_pipeline_stage(), AsyncTaskChain::get_next_wake_time(), AsyncTaskChain::set_num_threads(), GraphicsEngine::set_threading_model(), and PartBundle::write().
|
inlinestatic |
Returns true if a real threading library is available that supports actual OS-implemented threads, or false if the only threading we can provide is simulated user-space threading.
Definition at line 201 of file thread.I.
References is_simple_threads().
Referenced by is_threading_supported(), GraphicsEngine::render_frame(), and NodePath::verify_complete().
|
inline |
Blocks the calling process until the thread terminates.
If the thread has already terminated, this returns immediately.
Definition at line 298 of file thread.I.
References preempt().
Referenced by AsyncTaskChain::get_next_wake_time(), and is_joinable().
void Thread::output_blocker | ( | ostream & | out | ) | const |
Writes a description of the mutex or condition variable that this thread is blocked on.
Writes nothing if there is no blocker, or if we are not in DEBUG_THREADS mode.
Definition at line 190 of file thread.cxx.
References start().
Referenced by set_pipeline_stage().
|
inline |
Indicates that this thread should run as soon as possible, preemptying any other threads that may be scheduled to run.
This may not be implemented on every platform.
Definition at line 315 of file thread.I.
References get_current_task().
|
inlinestatic |
Should be called by the main thread just before exiting the program, this blocks until any remaining thread cleanup has finished.
Definition at line 341 of file thread.I.
References set_pstats_index().
Referenced by PandaFramework::close_framework(), get_current_task(), and GraphicsEngine::remove_all_windows().
|
inline |
Sets this thread's pipeline stage number to at least the indicated value, unless it is already larger.
See set_pipeline_stage().
Definition at line 96 of file thread.I.
References get_main_thread(), and set_pipeline_stage().
Referenced by get_pipeline_stage().
void Thread::set_pipeline_stage | ( | int | pipeline_stage | ) |
Specifies the Pipeline stage number associated with this thread.
The default stage is 0 if no stage is specified otherwise.
This must be a value in the range [0 .. pipeline->get_num_stages() - 1]. It specifies the values that this thread observes for all pipelined data. Typically, an application thread will leave this at 0, but a render thread may set it to 1 or 2 (to operate on the previous frame's data, or the second previous frame's data).
Definition at line 158 of file thread.cxx.
References output_blocker().
Referenced by set_min_pipeline_stage().
|
inline |
Stores a PStats callback to be associated with this thread.
This is used internally by the PStatClient; you should not need to call this directly.
Definition at line 365 of file thread.I.
References get_pstats_callback().
Referenced by set_pstats_index().
|
inline |
Stores a PStats index to be associated with this thread.
This is used internally by the PStatClient; you should not need to call this directly.
Definition at line 353 of file thread.I.
References set_pstats_callback().
Referenced by prepare_for_exit().
|
inlinestatic |
Suspends the current thread for at least the indicated amount of time.
It might be suspended for longer.
Definition at line 236 of file thread.I.
References force_yield().
Referenced by is_simple_threads(), PStatServer::main_loop(), ModelLoadRequest::ModelLoadRequest(), ModelSaveRequest::ModelSaveRequest(), and ClockObject::sync_frame_time().
bool Thread::start | ( | ThreadPriority | priority, |
bool | joinable | ||
) |
Starts the thread executing.
It is only valid to call this once.
The thread will begin executing its thread_main() function, and will terminate when thread_main() returns.
priority is intended as a hint to the relative importance of this thread. This may be ignored by the thread implementation.
joinable should be set true if you intend to call join() to wait for the thread to terminate, or false if you don't care and you will never call join(). Note that the reference count on the Thread object is incremented while the thread itself is running, so if you just want to fire and forget a thread, you may pass joinable = false, and never store the Thread object. It will automatically destruct itself when it finishes.
The return value is true if the thread is successfully started, false otherwise.
Definition at line 242 of file thread.cxx.
References get_main_thread(), preempt(), ReferenceCount::ref(), and Thread::PStatsCallback::~PStatsCallback().
Referenced by output_blocker(), and PfmFile::reverse_rows().