Panda3D
|
00001 // Filename: threadPosixImpl.h 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 #ifndef THREADPOSIXIMPL_H 00016 #define THREADPOSIXIMPL_H 00017 00018 #include "pandabase.h" 00019 #include "selectThreadImpl.h" 00020 00021 #ifdef THREAD_POSIX_IMPL 00022 00023 #include "pnotify.h" 00024 #include "threadPriority.h" 00025 #include "mutexPosixImpl.h" 00026 00027 #include <pthread.h> 00028 00029 class Thread; 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Class : ThreadPosixImpl 00033 // Description : Uses Posix threads to implement a thread. 00034 //////////////////////////////////////////////////////////////////// 00035 class EXPCL_PANDA_PIPELINE ThreadPosixImpl { 00036 public: 00037 INLINE ThreadPosixImpl(Thread *parent_obj); 00038 ~ThreadPosixImpl(); 00039 00040 void setup_main_thread(); 00041 bool start(ThreadPriority priority, bool joinable); 00042 void join(); 00043 INLINE void preempt(); 00044 00045 string get_unique_id() const; 00046 00047 INLINE static void prepare_for_exit(); 00048 00049 INLINE static Thread *get_current_thread(); 00050 INLINE static void bind_thread(Thread *thread); 00051 INLINE static bool is_threading_supported(); 00052 INLINE static bool is_true_threads(); 00053 INLINE static bool is_simple_threads(); 00054 INLINE static void sleep(double seconds); 00055 INLINE static void yield(); 00056 INLINE static void consider_yield(); 00057 00058 private: 00059 static void *root_func(void *data); 00060 static void init_pt_ptr_index(); 00061 00062 // There appears to be a name collision with the word "Status". 00063 enum PStatus { 00064 S_new, 00065 S_start_called, 00066 S_running, 00067 S_finished, 00068 }; 00069 00070 MutexPosixImpl _mutex; 00071 Thread *_parent_obj; 00072 pthread_t _thread; 00073 bool _joinable; 00074 bool _detached; 00075 PStatus _status; 00076 00077 static pthread_key_t _pt_ptr_index; 00078 static bool _got_pt_ptr_index; 00079 }; 00080 00081 #include "threadPosixImpl.I" 00082 00083 #endif // THREAD_POSIX_IMPL 00084 00085 #endif