14#ifndef THREADSIMPLEMANAGER_H
15#define THREADSIMPLEMANAGER_H
20#ifdef THREAD_SIMPLE_IMPL
29#ifdef HAVE_POSIX_THREADS
33#ifndef WIN32_LEAN_AND_MEAN
34#define WIN32_LEAN_AND_MEAN 1
40class ThreadSimpleImpl;
55class EXPCL_PANDA_PIPELINE ThreadSimpleManager {
57 ThreadSimpleManager();
60 void enqueue_ready(ThreadSimpleImpl *thread,
bool volunteer);
61 void enqueue_sleep(ThreadSimpleImpl *thread,
double seconds);
62 void enqueue_block(ThreadSimpleImpl *thread, BlockerSimple *blocker);
63 bool unblock_one(BlockerSimple *blocker);
64 bool unblock_all(BlockerSimple *blocker);
65 void enqueue_finished(ThreadSimpleImpl *thread);
66 void preempt(ThreadSimpleImpl *thread);
69 void prepare_for_exit();
71 INLINE ThreadSimpleImpl *get_current_thread();
72 void set_current_thread(ThreadSimpleImpl *current_thread);
73 INLINE
bool is_same_system_thread()
const;
74 void remove_thread(ThreadSimpleImpl *thread);
75 static void system_sleep(
double seconds);
76 static void system_yield();
78 double get_current_time()
const;
79 INLINE
static ThreadSimpleManager *get_global_ptr();
81 void write_status(std::ostream &out)
const;
84 static void init_pointers();
86 typedef pdeque<ThreadSimpleImpl *> FifoThreads;
87 typedef pvector<ThreadSimpleImpl *> Sleeping;
89 static void st_choose_next_context(
struct ThreadContext *from_context,
void *data);
90 void choose_next_context(
struct ThreadContext *from_context);
91 void do_timeslice_accounting(ThreadSimpleImpl *thread,
double now);
92 void wake_sleepers(Sleeping &sleepers,
double now);
93 void wake_all_sleepers(Sleeping &sleepers);
94 void report_deadlock();
95 double determine_timeslice(ThreadSimpleImpl *chosen_thread);
96 void kill_non_joinable(FifoThreads &threads);
97 void kill_non_joinable(Sleeping &threads);
100 class CompareStartTime {
102 INLINE
bool operator ()(ThreadSimpleImpl *a, ThreadSimpleImpl *b)
const;
107 ConfigVariableDouble _simple_thread_epoch_timeslice;
108 ConfigVariableDouble _simple_thread_volunteer_delay;
109 ConfigVariableDouble _simple_thread_yield_sleep;
110 ConfigVariableDouble _simple_thread_window;
111 ConfigVariableDouble _simple_thread_low_weight;
112 ConfigVariableDouble _simple_thread_normal_weight;
113 ConfigVariableDouble _simple_thread_high_weight;
114 ConfigVariableDouble _simple_thread_urgent_weight;
117 ThreadSimpleImpl *
volatile _current_thread;
125 FifoThreads _next_ready;
128 typedef pmap<BlockerSimple *, FifoThreads> Blocked;
139 Sleeping _volunteers;
142 FifoThreads _finished;
144 ThreadSimpleImpl *_waiting_for_exit;
152 unsigned int _tick_count;
153 ThreadSimpleImpl *_thread;
155 typedef pdeque<TickRecord> TickRecords;
156 TickRecords _tick_records;
157 unsigned int _total_ticks;
159 static bool _pointers_initialized;
160 static ThreadSimpleManager *_global_ptr;
A thread; that is, a lightweight process.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.