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

panda/src/express/thread.h

Go to the documentation of this file.
00001 // Filename: thread.h
00002 // Created by:  cary (16Sep98)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef THREAD_H
00020 #define THREAD_H
00021 
00022 #include "pandabase.h"
00023 #include "typedReferenceCount.h"
00024 #include "threadPriority.h"
00025 #include "threadImpl.h"
00026 #include "notify.h"
00027 
00028 ////////////////////////////////////////////////////////////////////
00029 //       Class : Thread
00030 // Description : A thread; that is, a lightweight process.  This is an
00031 //               abstract base class; to use it, you must subclass
00032 //               from it and redefine thread_main().
00033 //
00034 //               The thread itself will keep a reference count on the
00035 //               Thread object while it is running; when the thread
00036 //               returns from its root function, the Thread object
00037 //               will automatically be destructed if no other pointers
00038 //               are referencing it.
00039 ////////////////////////////////////////////////////////////////////
00040 class EXPCL_PANDAEXPRESS Thread : public TypedReferenceCount {
00041 public:
00042   INLINE Thread(const string &name);
00043   virtual ~Thread();
00044 
00045 private:
00046   INLINE Thread(const Thread &copy);
00047   INLINE void operator = (const Thread &copy);
00048 
00049 protected:
00050   virtual void thread_main()=0;
00051 
00052 public:
00053   INLINE const string &get_name() const;
00054 
00055   INLINE bool start(ThreadPriority priority, bool global, bool joinable);
00056   INLINE void join();
00057 
00058   INLINE static void prepare_for_exit();
00059 
00060   INLINE static Thread *get_current_thread();
00061   INLINE static bool is_threading_supported();
00062   INLINE static void sleep(double seconds);
00063 
00064   virtual void output(ostream &out) const;
00065 
00066 private:
00067   bool _started;
00068   string _name;
00069   ThreadImpl _impl;
00070   friend class ThreadDummyImpl;
00071   friend class ThreadNsprImpl;
00072 
00073 
00074 public:
00075   static TypeHandle get_class_type() {
00076     return _type_handle;
00077   }
00078   static void init_type() {
00079     TypedReferenceCount::init_type();
00080     register_type(_type_handle, "Thread",
00081                   TypedReferenceCount::get_class_type());
00082   }
00083 
00084 private:
00085   static TypeHandle _type_handle;
00086 };
00087 
00088 INLINE ostream &operator << (ostream &out, const Thread &thread);
00089 
00090 #include "thread.I"
00091 
00092 #endif

Generated on Fri May 2 00:38:41 2003 for Panda by doxygen1.3