Panda3D
threadSimpleImpl.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file threadSimpleImpl.I
10  * @author drose
11  * @date 2007-06-18
12  */
13 
14 /**
15  *
16  */
17 INLINE Thread *ThreadSimpleImpl::
18 get_current_thread() {
19  return ThreadSimpleManager::get_global_ptr()->get_current_thread()->_parent_obj;
20 }
21 
22 /**
23  * Returns true if we are still running within the same OS-level thread that
24  * this thread begin in, or false if this appears to be running in a different
25  * thread.
26  */
27 INLINE bool ThreadSimpleImpl::
28 is_same_system_thread() const {
29 #ifdef HAVE_POSIX_THREADS
30  return pthread_equal(_posix_system_thread_id, pthread_self());
31 #endif
32 #ifdef WIN32
33  return (_win32_system_thread_id == GetCurrentThreadId());
34 #endif
35  return true;
36 }
37 
38 /**
39  * Associates the indicated Thread object with the currently-executing thread.
40  * You should not call this directly; use Thread::bind_thread() instead.
41  */
42 INLINE void ThreadSimpleImpl::
43 bind_thread(Thread *) {
44 }
45 
46 /**
47  *
48  */
49 INLINE bool ThreadSimpleImpl::
50 is_threading_supported() {
51  return true;
52 }
53 
54 /**
55  *
56  */
57 INLINE bool ThreadSimpleImpl::
58 is_simple_threads() {
59  return true;
60 }
61 
62 /**
63  *
64  */
65 INLINE void ThreadSimpleImpl::
66 sleep(double seconds) {
67  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
68  if (manager->is_same_system_thread()) {
69  ThreadSimpleImpl *thread = manager->get_current_thread();
70  thread->sleep_this(seconds);
71  } else {
72  manager->system_sleep(seconds);
73  }
74 }
75 
76 /**
77  *
78  */
79 INLINE void ThreadSimpleImpl::
80 yield() {
81  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
82  if (manager->is_same_system_thread()) {
83  ThreadSimpleImpl *thread = manager->get_current_thread();
84  thread->yield_this(true);
85  } else {
86  manager->system_yield();
87  }
88 }
89 
90 /**
91  *
92  */
93 INLINE void ThreadSimpleImpl::
94 consider_yield() {
95  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
96  if (manager->is_same_system_thread()) {
97  ThreadSimpleImpl *thread = manager->get_current_thread();
98  thread->consider_yield_this();
99  }
100 }
101 
102 /**
103  *
104  */
105 INLINE void ThreadSimpleImpl::
106 consider_yield_this() {
107  double now = _manager->get_current_time();
108  if (now >= _stop_time) {
109  yield_this(false);
110  }
111 }
112 
113 /**
114  *
115  */
116 INLINE double ThreadSimpleImpl::
117 get_wake_time() const {
118  return _wake_time;
119 }
120 
121 /**
122  * Writes a list of threads running and threads blocked.
123  */
124 void ThreadSimpleImpl::
125 write_status(std::ostream &out) {
126  ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
127  manager->write_status(out);
128 }
get_current_thread
Returns a pointer to the currently-executing Thread object.
Definition: thread.h:109
A thread; that is, a lightweight process.
Definition: thread.h:46