Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Thread Class Reference

A thread; that is, a lightweight process. More...

#include <thread.h>

Inheritance diagram for Thread:

TypedReferenceCount TypedObject ReferenceCount GraphicsEngine::RenderThread philosopher ThreadWithData List of all members.

Public Member Functions

 Thread (const string &name)
 Creates a new Thread object, but does not immediately start executing it.

virtual ~Thread ()
const string & get_name () const
 Returns the name of the thread.

bool start (ThreadPriority priority, bool global, bool joinable)
 Starts the thread executing.

void join ()
 Blocks the calling process until the thread terminates.

virtual void output (ostream &out) const
virtual TypeHandle get_type () const
virtual TypeHandle force_init_type ()
int get_type_index () const
 Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

bool is_of_type (TypeHandle handle) const
 Returns true if the current object is or derives from the indicated type.

bool is_exact_type (TypeHandle handle) const
 Returns true if the current object is the indicated type exactly.

int get_ref_count () const
 Returns the current reference count.

int ref () const
 Explicitly increments the reference count.

int unref () const
 Explicitly decrements the reference count.

void test_ref_count_integrity () const
 Does some easy checks to make sure that the reference count isn't completely bogus.


Static Public Member Functions

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.

Thread * get_current_thread ()
 Returns a pointer to the currently-executing Thread object, or NULL if the main thread (or some system thread other than one started from the Panda interface) is currently executing.

bool is_threading_supported ()
 Returns true if a real threading library is available that supports threads, or false if no threading library is available (and Thread::start() will always fail).

void sleep (double seconds)
 Suspends the current thread for at least the indicated amount of time.

TypeHandle get_class_type ()
void init_type ()

Protected Member Functions

virtual void thread_main ()=0

Private Member Functions

 Thread (const Thread &copy)
 Do not attempt to copy threads.

void operator= (const Thread &copy)
 Do not attempt to copy threads.


Private Attributes

bool _started
string _name
ThreadImpl _impl

Static Private Attributes

TypeHandle _type_handle

Friends

class ThreadDummyImpl
class ThreadNsprImpl

Detailed Description

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.

Definition at line 54 of file thread.h.


Constructor & Destructor Documentation

Thread::Thread const string &  name  )  [inline]
 

Creates a new Thread object, but does not immediately start executing it.

This gives the caller a chance to store it in a PT(Thread) object, if desired, before the thread gets a chance to terminate and destruct itself.

Call start() to begin thread execution.

Definition at line 44 of file thread.I.

Thread::~Thread  )  [virtual]
 

Definition at line 34 of file thread.cxx.

References get_name(), and TypedReferenceCount::get_type().

Thread::Thread const Thread &  copy  )  [inline, private]
 

Do not attempt to copy threads.

Definition at line 57 of file thread.I.

References _name, and INLINE.


Member Function Documentation

virtual TypeHandle TypedReferenceCount::force_init_type void   )  [inline, virtual, inherited]
 

Implements TypedObject.

Reimplemented in CollisionEntry, CollisionHandler, CollisionHandlerEvent, CollisionHandlerFloor, CollisionHandlerPhysical, CollisionHandlerPusher, CollisionHandlerQueue, CRGraphicsStateGuardian, CRSavedFrameBuffer, ClientAnalogDevice, ClientBase, ClientButtonDevice, ClientDevice, ClientDialDevice, ClientTrackerDevice, GraphicsChannel, GraphicsLayer, GraphicsPipe, GraphicsStateGuardian, GraphicsWindow, HardwareChannel, SavedFrameBuffer, CylindricalLens, FisheyeLens, PSphereLens, DXGraphicsStateGuardian7, DXSavedFrameBuffer7, wdxGraphicsPipe7, wdxGraphicsWindow7, DXGraphicsStateGuardian8, DXSavedFrameBuffer8, wdxGraphicsPipe8, wdxGraphicsWindow8, EggAnimData, EggBin, EggBinMaker, EggComment, EggCoordinateSystem, EggCurve, EggData, EggExternalReference, EggFilenameNode, EggGroup, EggGroupNode, EggGroupUniquifier, EggMaterial, EggNamedObject, EggNameUniquifier, EggNode, EggNurbsCurve, EggNurbsSurface, EggObject, EggPoint, EggPolygon, EggPoolUniquifier, EggPrimitive, EggSAnimData, EggSurface, EggSwitchCondition, EggTable, EggTexture, EggVertex, EggVertexPool, EggXfmAnimData, EggXfmSAnim, Event, EventStoreValueBase, EventStoreValue< Type >, VirtualFile, VirtualFileComposite, VirtualFileSimple, WindowFramework, GLGraphicsStateGuardian, GLSavedFrameBuffer, glxGraphicsPipe, glxGraphicsStateGuardian, glxGraphicsWindow, Lens, MatrixLens, OrthographicLens, PerspectiveLens, GraphicsStateGuardianBase, Lerp, AutonomousLerp, LerpBlendType, EaseInBlendType, EaseOutBlendType, EaseInOutBlendType, NoBlendType, LerpFunctor, SimpleLerpFunctor< value >, SimpleQueryLerpFunctor< value >, MultiLerpFunctor, BoundingHexahedron, BoundingLine, BoundingSphere, BoundingVolume, FiniteBoundingVolume, GeometricBoundingVolume, OmniBoundingVolume, CullBin, CullBinBackToFront, CullBinFixed, CullBinFrontToBack, CullBinUnsorted, PosLerpFunctor, HprLerpFunctor, ScaleLerpFunctor, ColorLerpFunctor, PosHprLerpFunctor, HprScaleLerpFunctor, PosHprScaleLerpFunctor, ColorScaleLerpFunctor, EventStoreTransform, PGMouseWatcherBackground, PGMouseWatcherParameter, PGMouseWatcherRegion, AngularForce, AngularVectorForce, BaseForce, LinearCylinderVortexForce, LinearDistanceForce, LinearForce, LinearFrictionForce, LinearJitterForce, LinearNoiseForce, LinearRandomForce, LinearSinkForce, LinearSourceForce, LinearUserDefinedForce, LinearVectorForce, Physical, PhysicsObject, BamReaderParam, ButtonEventList, FactoryParam, WritableParam, RIBGraphicsWindow, RIBGraphicsStateGuardian, TextFont, MouseWatcherRegion, VrpnAnalogDevice, VrpnButtonDevice, VrpnClient, VrpnDialDevice, VrpnTrackerDevice, wcrGraphicsWindow, wglGraphicsPipe, wglGraphicsStateGuardian, wglGraphicsWindow, WinGraphicsPipe, WinGraphicsWindow, SimpleLerpFunctor< LPoint3f >, SimpleLerpFunctor< LVecBase3f >, and SimpleLerpFunctor< LVecBase4f >.

Definition at line 59 of file typedReferenceCount.h.

TypeHandle Thread::get_class_type void   )  [inline, static]
 

Reimplemented from TypedReferenceCount.

Definition at line 89 of file thread.h.

Thread * Thread::get_current_thread  )  [inline, static]
 

Returns a pointer to the currently-executing Thread object, or NULL if the main thread (or some system thread other than one started from the Panda interface) is currently executing.

Definition at line 191 of file thread.I.

const string & Thread::get_name  )  const [inline]
 

Returns the name of the thread.

Definition at line 83 of file thread.I.

References _impl, _started, INLINE, nassertr, and ThreadDummyImpl::start().

Referenced by ThreadWithData::ThreadWithData(), and ~Thread().

int ReferenceCount::get_ref_count  )  const [inline, inherited]
 

Returns the current reference count.

Definition at line 183 of file referenceCount.I.

Referenced by RenderState::determine_bin_index(), RenderEffects::determine_show_bounds(), FontPool::ns_garbage_collect(), TexturePool::ns_garbage_collect(), MaterialPool::ns_get_material(), and TexturePool::ns_release_texture().

virtual TypeHandle TypedReferenceCount::get_type void   )  const [inline, virtual, inherited]
 

Implements TypedObject.

Reimplemented in CollisionEntry, CollisionHandler, CollisionHandlerEvent, CollisionHandlerFloor, CollisionHandlerPhysical, CollisionHandlerPusher, CollisionHandlerQueue, CRGraphicsStateGuardian, CRSavedFrameBuffer, ClientAnalogDevice, ClientBase, ClientButtonDevice, ClientDevice, ClientDialDevice, ClientTrackerDevice, GraphicsChannel, GraphicsLayer, GraphicsPipe, GraphicsStateGuardian, GraphicsWindow, HardwareChannel, SavedFrameBuffer, CylindricalLens, FisheyeLens, PSphereLens, DXGraphicsStateGuardian7, DXSavedFrameBuffer7, wdxGraphicsPipe7, wdxGraphicsWindow7, DXGraphicsStateGuardian8, DXSavedFrameBuffer8, wdxGraphicsPipe8, wdxGraphicsWindow8, EggAnimData, EggBin, EggBinMaker, EggComment, EggCoordinateSystem, EggCurve, EggData, EggExternalReference, EggFilenameNode, EggGroup, EggGroupNode, EggGroupUniquifier, EggMaterial, EggNamedObject, EggNameUniquifier, EggNode, EggNurbsCurve, EggNurbsSurface, EggObject, EggPoint, EggPolygon, EggPoolUniquifier, EggPrimitive, EggSAnimData, EggSurface, EggSwitchCondition, EggSwitchConditionDistance, EggTable, EggTexture, EggVertex, EggVertexPool, EggXfmAnimData, EggXfmSAnim, Event, EventStoreValueBase, EventStoreValue< Type >, VirtualFile, VirtualFileComposite, VirtualFileSimple, WindowFramework, GLGraphicsStateGuardian, GLSavedFrameBuffer, glxGraphicsPipe, glxGraphicsStateGuardian, glxGraphicsWindow, Lens, MatrixLens, OrthographicLens, PerspectiveLens, GraphicsStateGuardianBase, Lerp, AutonomousLerp, LerpBlendType, EaseInBlendType, EaseOutBlendType, EaseInOutBlendType, NoBlendType, LerpFunctor, SimpleLerpFunctor< value >, SimpleQueryLerpFunctor< value >, MultiLerpFunctor, BoundingHexahedron, BoundingLine, BoundingSphere, BoundingVolume, FiniteBoundingVolume, GeometricBoundingVolume, OmniBoundingVolume, CullBin, CullBinBackToFront, CullBinFixed, CullBinFrontToBack, CullBinUnsorted, PosLerpFunctor, HprLerpFunctor, ScaleLerpFunctor, ColorLerpFunctor, PosHprLerpFunctor, HprScaleLerpFunctor, PosHprScaleLerpFunctor, ColorScaleLerpFunctor, EventStoreTransform, PGMouseWatcherBackground, PGMouseWatcherParameter, PGMouseWatcherRegion, AngularForce, AngularVectorForce, BaseForce, LinearCylinderVortexForce, LinearDistanceForce, LinearForce, LinearFrictionForce, LinearJitterForce, LinearNoiseForce, LinearRandomForce, LinearSinkForce, LinearSourceForce, LinearUserDefinedForce, LinearVectorForce, Physical, PhysicsObject, BamReaderParam, ButtonEventList, FactoryParam, WritableParam, RIBGraphicsWindow, RIBGraphicsStateGuardian, TextFont, MouseWatcherRegion, VrpnAnalogDevice, VrpnButtonDevice, VrpnClient, VrpnDialDevice, VrpnTrackerDevice, wcrGraphicsWindow, wglGraphicsPipe, wglGraphicsStateGuardian, wglGraphicsWindow, WinGraphicsPipe, WinGraphicsWindow, SimpleLerpFunctor< LPoint3f >, SimpleLerpFunctor< LVecBase3f >, and SimpleLerpFunctor< LVecBase4f >.

Definition at line 56 of file typedReferenceCount.h.

Referenced by ~Thread().

int TypedObject::get_type_index  )  const [inline, inherited]
 

Returns the internal index number associated with this object's TypeHandle, a unique number for each different type.

This is equivalent to get_type().get_index().

Definition at line 71 of file typedObject.I.

References TypeHandle::get_name(), TypedObject::get_type(), and INLINE.

void Thread::init_type void   )  [inline, static]
 

Reimplemented from TypedReferenceCount.

Definition at line 92 of file thread.h.

bool TypedObject::is_exact_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is the indicated type exactly.

Definition at line 101 of file typedObject.I.

Referenced by PT(), and CollisionNode::xform().

bool TypedObject::is_of_type TypeHandle  handle  )  const [inline, inherited]
 

Returns true if the current object is or derives from the indicated type.

Definition at line 86 of file typedObject.I.

Referenced by EggMaterialCollection::collapse_equivalent_materials(), EggTextureCollection::collapse_equivalent_textures(), DeferredNodeProperty::compose(), AnimBundleMaker::create_s_channel(), CharacterMaker::create_slider(), ProjectionScreen::cull_callback(), DataNode::define_output(), EggNode::determine_draw_order(), CharacterMaker::egg_to_index(), EggGroupUniquifier::EggGroupUniquifier(), EggPoolUniquifier::EggPoolUniquifier(), EggGroupNode::find_textures(), StaticTextFont::get_glyph(), EggMaterialCollection::insert_materials(), EggTextureCollection::insert_textures(), CharacterJoint::make_copy(), PT(), EggGroupNode::r_flatten_transforms(), EggGroupNode::r_transform_vertices(), EggGroupNode::recompute_polygon_normals(), CollisionLevelState::reserve(), PandaFramework::reset_frame_rate(), PandaFramework::set_texture(), EggGroupNode::steal_children(), and DataGraphTraverser::traverse().

bool Thread::is_threading_supported  )  [inline, static]
 

Returns true if a real threading library is available that supports threads, or false if no threading library is available (and Thread::start() will always fail).

Definition at line 210 of file thread.I.

void Thread::join  )  [inline]
 

Blocks the calling process until the thread terminates.

If the thread has already terminated, this returns immediately.

Definition at line 155 of file thread.I.

References INLINE, and ThreadDummyImpl::sleep().

void Thread::operator= const Thread &  copy  )  [inline, private]
 

Do not attempt to copy threads.

Definition at line 70 of file thread.I.

void Thread::output ostream &  out  )  const [virtual]
 

Definition at line 45 of file thread.cxx.

void Thread::prepare_for_exit  )  [inline, static]
 

Should be called by the main thread just before exiting the program, this blocks until any remaining thread cleanup has finished.

Definition at line 172 of file thread.I.

int ReferenceCount::ref  )  const [inline, inherited]
 

Explicitly increments the reference count.

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

The return value is the new reference count.

Definition at line 225 of file referenceCount.I.

Referenced by ClientDevice::ClientDevice(), EggGroupNode::find_textures(), EggGroupNode::r_apply_texmats(), EggGroupNode::r_flatten_transforms(), and EggGroupNode::reverse_vertex_ordering().

void Thread::sleep double  seconds  )  [inline, static]
 

Suspends the current thread for at least the indicated amount of time.

It might be suspended for longer.

Definition at line 227 of file thread.I.

bool Thread::start ThreadPriority  priority,
bool  global,
bool  joinable
[inline]
 

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, and global should be set true if the thread will perform a lot of blocking I/O, or false otherwise (see the NSPR documentation on global vs. local threads for more on this). Both of these parameters 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().

The return value is true if the thread is successfully started, false otherwise.

Definition at line 136 of file thread.I.

References INLINE, and ThreadDummyImpl::is_threading_supported().

void ReferenceCount::test_ref_count_integrity  )  const [inline, inherited]
 

Does some easy checks to make sure that the reference count isn't completely bogus.

Definition at line 328 of file referenceCount.I.

References INLINE.

Referenced by EggNode::determine_bin(), and ReferenceCount::~ReferenceCount().

virtual void Thread::thread_main  )  [protected, pure virtual]
 

Implemented in GraphicsEngine::RenderThread, philosopher, and ThreadWithData.

int ReferenceCount::unref  )  const [inline, inherited]
 

Explicitly decrements the reference count.

Note that the object will not be implicitly deleted by unref() simply because the reference count drops to zero. (Having a member function delete itself is problematic; plus, we don't have a virtual destructor anyway.) However, see the helper function unref_delete().

User code should avoid using ref() and unref() directly, which can result in missed reference counts. Instead, let a PointerTo object manage the reference counting automatically.

This function is const, even though it changes the object, because generally fiddling with an object's reference count isn't considered part of fiddling with the object. An object might be const in other ways, but we still need to accurately count the number of references to it.

The return value is the new reference count.

Definition at line 293 of file referenceCount.I.

References INLINE.

Referenced by RenderState::determine_bin_index(), and RenderEffects::determine_show_bounds().


Friends And Related Function Documentation

friend class ThreadDummyImpl [friend]
 

Definition at line 84 of file thread.h.

friend class ThreadNsprImpl [friend]
 

Definition at line 85 of file thread.h.


Member Data Documentation

ThreadImpl Thread::_impl [private]
 

Definition at line 83 of file thread.h.

Referenced by get_name().

string Thread::_name [private]
 

Definition at line 82 of file thread.h.

Referenced by Thread().

bool Thread::_started [private]
 

Definition at line 81 of file thread.h.

Referenced by get_name().

TypeHandle Thread::_type_handle [static, private]
 

Reimplemented from TypedReferenceCount.

Definition at line 24 of file thread.cxx.


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:55:37 2003 for Panda by doxygen1.3