18 #include "pandabase.h"
20 #include "typedReferenceCount.h"
21 #include "pointerTo.h"
22 #include "threadPriority.h"
23 #include "threadImpl.h"
25 #include "config_pipeline.h"
28 #undef _POSIX_C_SOURCE
35 class ConditionVarDebug;
36 class ConditionVarFullDebug;
53 Thread(
const string &name,
const string &sync_name);
60 INLINE
void operator = (
const Thread ©);
63 virtual void thread_main()=0;
66 static PT(Thread) bind_thread(
const string &name,
const string &sync_name);
68 INLINE
const string &get_sync_name()
const;
70 INLINE
int get_pstats_index()
const;
71 INLINE
string get_unique_id()
const;
73 INLINE
int get_pipeline_stage()
const;
74 void set_pipeline_stage(
int pipeline_stage);
75 INLINE
void set_min_pipeline_stage(
int min_pipeline_stage);
77 INLINE
static Thread *get_main_thread();
78 INLINE
static Thread *get_external_thread();
79 INLINE
static Thread *get_current_thread();
80 INLINE
static int get_current_pipeline_stage();
81 INLINE
static bool is_threading_supported();
82 INLINE
static bool is_true_threads();
83 INLINE
static bool is_simple_threads();
84 BLOCKING INLINE
static void sleep(
double seconds);
86 BLOCKING INLINE
static void force_yield();
87 BLOCKING INLINE
static void consider_yield();
89 virtual void output(ostream &out)
const;
90 void output_blocker(ostream &out)
const;
91 static void write_status(ostream &out);
93 INLINE
bool is_started()
const;
94 INLINE
bool is_joinable()
const;
96 bool start(ThreadPriority priority,
bool joinable);
97 BLOCKING INLINE
void join();
98 INLINE
void preempt();
101 void set_python_data(PyObject *python_data);
102 PyObject *get_python_data()
const;
107 INLINE
static void prepare_for_exit();
115 virtual void deactivate_hook(Thread *thread);
116 virtual void activate_hook(Thread *thread);
119 INLINE
void set_pstats_index(
int pstats_index);
125 PyObject *call_python_func(PyObject *
function, PyObject *args);
126 void handle_python_exception();
127 #endif // HAVE_PYTHON
130 static void init_main_thread();
131 static void init_external_thread();
146 PyObject *_python_data;
150 MutexDebug *_blocked_on_mutex;
151 ConditionVarDebug *_waiting_on_cvar;
152 ConditionVarFullDebug *_waiting_on_cvar_full;
153 #endif // DEBUG_THREADS
156 static Thread *_main_thread;
157 static Thread *_external_thread;
163 static void init_type() {
164 TypedReferenceCount::init_type();
165 Namable::init_type(),
166 register_type(_type_handle,
"Thread",
167 TypedReferenceCount::get_class_type(),
168 Namable::get_class_type());
171 return get_class_type();
173 virtual TypeHandle force_init_type() {init_type();
return get_class_type();}
178 friend class MutexDebug;
179 friend class ConditionVarDebug;
180 friend class ConditionVarFullDebug;
182 friend class ThreadDummyImpl;
183 friend class ThreadWin32Impl;
184 friend class ThreadPosixImpl;
185 friend class ThreadSimpleImpl;
190 INLINE ostream &operator << (ostream &out,
const Thread &thread);
The abstract base class for AsyncTask.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
A standard mutex, or mutual exclusion lock.
A base class for all things which can have a name.
The special "main thread" class.
void output(ostream &out) const
Outputs the Namable.
A thread; that is, a lightweight process.
TypeHandle is the identifier used to differentiate C++ class types.