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