Panda3D

genericThread.h

00001 // Filename: genericThread.h
00002 // Created by:  drose (09Nov11)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef GENERICTHREAD_H
00016 #define GENERICTHREAD_H
00017 
00018 #include "pandabase.h"
00019 #include "thread.h"
00020 
00021 ////////////////////////////////////////////////////////////////////
00022 //       Class : GenericThread
00023 // Description : A generic thread type that allows calling a C-style thread
00024 //               function without having to subclass.
00025 ////////////////////////////////////////////////////////////////////
00026 class EXPCL_PANDA_PIPELINE GenericThread : public Thread {
00027 public:
00028   typedef void ThreadFunc(void *user_data);
00029 
00030   GenericThread(const string &name, const string &sync_name);
00031   GenericThread(const string &name, const string &sync_name, ThreadFunc *function, void *user_data);
00032 
00033   INLINE void set_function(ThreadFunc *function);
00034   INLINE ThreadFunc *get_function() const;
00035 
00036   INLINE void set_user_data(void *user_data);
00037   INLINE void *get_user_data() const;
00038 
00039 protected:
00040   virtual void thread_main();
00041 
00042 private:
00043   ThreadFunc *_function;
00044   void *_user_data;
00045 
00046 public:
00047   static TypeHandle get_class_type() {
00048     return _type_handle;
00049   }
00050   static void init_type() {
00051     Thread::init_type();
00052     register_type(_type_handle, "GenericThread",
00053                   Thread::get_class_type());
00054   }
00055   virtual TypeHandle get_type() const {
00056     return get_class_type();
00057   }
00058   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00059 
00060 private:
00061   static TypeHandle _type_handle;
00062 };
00063 
00064 #include "genericThread.I"
00065 
00066 #endif
00067 
 All Classes Functions Variables Enumerations