Panda3D
 All Classes Functions Variables Enumerations
genericThread.h
1 // Filename: genericThread.h
2 // Created by: drose (09Nov11)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef GENERICTHREAD_H
16 #define GENERICTHREAD_H
17 
18 #include "pandabase.h"
19 #include "thread.h"
20 
21 ////////////////////////////////////////////////////////////////////
22 // Class : GenericThread
23 // Description : A generic thread type that allows calling a C-style thread
24 // function without having to subclass.
25 ////////////////////////////////////////////////////////////////////
26 class EXPCL_PANDA_PIPELINE GenericThread : public Thread {
27 public:
28  typedef void ThreadFunc(void *user_data);
29 
30  GenericThread(const string &name, const string &sync_name);
31  GenericThread(const string &name, const string &sync_name, ThreadFunc *function, void *user_data);
32 
33  INLINE void set_function(ThreadFunc *function);
34  INLINE ThreadFunc *get_function() const;
35 
36  INLINE void set_user_data(void *user_data);
37  INLINE void *get_user_data() const;
38 
39 protected:
40  virtual void thread_main();
41 
42 private:
43  ThreadFunc *_function;
44  void *_user_data;
45 
46 public:
47  static TypeHandle get_class_type() {
48  return _type_handle;
49  }
50  static void init_type() {
51  Thread::init_type();
52  register_type(_type_handle, "GenericThread",
53  Thread::get_class_type());
54  }
55  virtual TypeHandle get_type() const {
56  return get_class_type();
57  }
58  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
59 
60 private:
61  static TypeHandle _type_handle;
62 };
63 
64 #include "genericThread.I"
65 
66 #endif
67 
A generic thread type that allows calling a C-style thread function without having to subclass...
Definition: genericThread.h:26
A thread; that is, a lightweight process.
Definition: thread.h:51
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85