Panda3D
|
00001 // Filename: threadPosixImpl.I 00002 // Created by: drose (09Feb06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: ThreadPosixImpl::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE ThreadPosixImpl:: 00022 ThreadPosixImpl(Thread *parent_obj) : 00023 _parent_obj(parent_obj) 00024 { 00025 _joinable = false; 00026 _detached = false; 00027 _status = S_new; 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: ThreadPosixImpl::preempt 00032 // Access: Public 00033 // Description: 00034 //////////////////////////////////////////////////////////////////// 00035 INLINE void ThreadPosixImpl:: 00036 preempt() { 00037 } 00038 00039 //////////////////////////////////////////////////////////////////// 00040 // Function: ThreadPosixImpl::prepare_for_exit 00041 // Access: Public 00042 // Description: 00043 //////////////////////////////////////////////////////////////////// 00044 INLINE void ThreadPosixImpl:: 00045 prepare_for_exit() { 00046 } 00047 00048 //////////////////////////////////////////////////////////////////// 00049 // Function: ThreadPosixImpl::get_current_thread 00050 // Access: Public, Static 00051 // Description: 00052 //////////////////////////////////////////////////////////////////// 00053 INLINE Thread *ThreadPosixImpl:: 00054 get_current_thread() { 00055 TAU_PROFILE("Thread *ThreadPosixImpl::get_current_thread()", " ", TAU_USER); 00056 if (!_got_pt_ptr_index) { 00057 init_pt_ptr_index(); 00058 } 00059 return (Thread *)pthread_getspecific(_pt_ptr_index); 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: ThreadPosixImpl::bind_thread 00064 // Access: Public, Static 00065 // Description: Associates the indicated Thread object with the 00066 // currently-executing thread. You should not call this 00067 // directly; use Thread::bind_thread() instead. 00068 //////////////////////////////////////////////////////////////////// 00069 INLINE void ThreadPosixImpl:: 00070 bind_thread(Thread *thread) { 00071 if (!_got_pt_ptr_index) { 00072 init_pt_ptr_index(); 00073 } 00074 int result = pthread_setspecific(_pt_ptr_index, thread); 00075 nassertv(result == 0); 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: ThreadPosixImpl::is_threading_supported 00080 // Access: Public, Static 00081 // Description: 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE bool ThreadPosixImpl:: 00084 is_threading_supported() { 00085 return true; 00086 } 00087 00088 //////////////////////////////////////////////////////////////////// 00089 // Function: ThreadPosixImpl::is_true_threads 00090 // Access: Public, Static 00091 // Description: 00092 //////////////////////////////////////////////////////////////////// 00093 INLINE bool ThreadPosixImpl:: 00094 is_true_threads() { 00095 return true; 00096 } 00097 00098 //////////////////////////////////////////////////////////////////// 00099 // Function: ThreadPosixImpl::is_simple_threads 00100 // Access: Public, Static 00101 // Description: 00102 //////////////////////////////////////////////////////////////////// 00103 INLINE bool ThreadPosixImpl:: 00104 is_simple_threads() { 00105 return false; 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: ThreadPosixImpl::sleep 00110 // Access: Public, Static 00111 // Description: 00112 //////////////////////////////////////////////////////////////////// 00113 INLINE void ThreadPosixImpl:: 00114 sleep(double seconds) { 00115 TAU_PROFILE("void ThreadPosixImpl::sleep(double)", " ", TAU_USER); 00116 struct timespec rqtp; 00117 rqtp.tv_sec = time_t(seconds); 00118 rqtp.tv_nsec = long((seconds - (double)rqtp.tv_sec) * 1000000000.0); 00119 nanosleep(&rqtp, NULL); 00120 } 00121 00122 //////////////////////////////////////////////////////////////////// 00123 // Function: ThreadPosixImpl::yield 00124 // Access: Public, Static 00125 // Description: 00126 //////////////////////////////////////////////////////////////////// 00127 INLINE void ThreadPosixImpl:: 00128 yield() { 00129 sleep(0.0); 00130 } 00131 00132 //////////////////////////////////////////////////////////////////// 00133 // Function: ThreadPosixImpl::consider_yield 00134 // Access: Public, Static 00135 // Description: 00136 //////////////////////////////////////////////////////////////////// 00137 INLINE void ThreadPosixImpl:: 00138 consider_yield() { 00139 }