Panda3D

threadPosixImpl.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 threadPosixImpl.I
10 * @author drose
11 * @date 2006-02-09
12 */
13
14 /**
15 *
16 */
17 INLINE ThreadPosixImpl::
18 ThreadPosixImpl(Thread *parent_obj) :
19 _parent_obj(parent_obj)
20 {
21 _joinable = false;
22 _detached = false;
23 _status = S_new;
24 #ifdef ANDROID
25 _jni_env = nullptr;
26 #endif
27 }
28
29 /**
30 *
31 */
32 INLINE void ThreadPosixImpl::
33 preempt() {
34 }
35
36 /**
37 *
38 */
39 INLINE void ThreadPosixImpl::
40 prepare_for_exit() {
41 }
42
43 /**
44 *
45 */
46 INLINE Thread *ThreadPosixImpl::
47 get_current_thread() {
48 TAU_PROFILE("Thread *ThreadPosixImpl::get_current_thread()", " ", TAU_USER);
49 if (!_got_pt_ptr_index) {
50 init_pt_ptr_index();
51 }
52 return (Thread *)pthread_getspecific(_pt_ptr_index);
53 }
54
55 /**
56 * Associates the indicated Thread object with the currently-executing thread.
57 * You should not call this directly; use Thread::bind_thread() instead.
58 */
59 INLINE void ThreadPosixImpl::
60 bind_thread(Thread *thread) {
61 if (!_got_pt_ptr_index) {
62 init_pt_ptr_index();
63 }
64 int result = pthread_setspecific(_pt_ptr_index, thread);
65 nassertv(result == 0);
66 #ifdef ANDROID
67 bind_java_thread();
68 #endif
69 }
70
71 /**
72 *
73 */
74 INLINE bool ThreadPosixImpl::
75 is_threading_supported() {
76 return true;
77 }
78
79 /**
80 *
81 */
82 INLINE bool ThreadPosixImpl::
83 is_true_threads() {
84 return true;
85 }
86
87 /**
88 *
89 */
90 INLINE bool ThreadPosixImpl::
91 is_simple_threads() {
92 return false;
93 }
94
95 /**
96 *
97 */
98 INLINE void ThreadPosixImpl::
99 sleep(double seconds) {
100 TAU_PROFILE("void ThreadPosixImpl::sleep(double)", " ", TAU_USER);
101 struct timespec rqtp;
102 rqtp.tv_sec = time_t(seconds);
103 rqtp.tv_nsec = long((seconds - (double)rqtp.tv_sec) * 1000000000.0);
104 nanosleep(&rqtp, nullptr);
105 }
106
107 /**
108 *
109 */
110 INLINE void ThreadPosixImpl::
111 yield() {
112 sleep(0.0);
113 }
114
115 /**
116 *
117 */
118 INLINE void ThreadPosixImpl::
119 consider_yield() {
120 }
121
122 #ifdef ANDROID
123 /**
124 * Returns the JNIEnv object for the current thread.
125 */
126 INLINE JNIEnv *ThreadPosixImpl::
127 get_jni_env() const {
128 return _jni_env;
129 }
130 #endif
Thread
A thread; that is, a lightweight process.
Definition: thread.h:46