Panda3D
|
00001 // Filename: threadWin32Impl.h 00002 // Created by: drose (07Feb06) 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 THREADWIN32IMPL_H 00016 #define THREADWIN32IMPL_H 00017 00018 #include "pandabase.h" 00019 #include "selectThreadImpl.h" 00020 00021 #ifdef THREAD_WIN32_IMPL 00022 00023 #include "pnotify.h" 00024 #include "threadPriority.h" 00025 #include "mutexWin32Impl.h" 00026 #include "conditionVarWin32Impl.h" 00027 00028 class Thread; 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : ThreadWin32Impl 00032 // Description : Uses native Windows calls to implement a thread. 00033 //////////////////////////////////////////////////////////////////// 00034 class EXPCL_PANDA_PIPELINE ThreadWin32Impl { 00035 public: 00036 INLINE ThreadWin32Impl(Thread *parent_obj); 00037 ~ThreadWin32Impl(); 00038 00039 void setup_main_thread(); 00040 bool start(ThreadPriority priority, bool joinable); 00041 void join(); 00042 INLINE void preempt(); 00043 00044 string get_unique_id() const; 00045 00046 INLINE static void prepare_for_exit(); 00047 00048 INLINE static Thread *get_current_thread(); 00049 INLINE static void bind_thread(Thread *thread); 00050 INLINE static bool is_threading_supported(); 00051 INLINE static bool is_true_threads(); 00052 INLINE static bool is_simple_threads(); 00053 INLINE static void sleep(double seconds); 00054 INLINE static void yield(); 00055 INLINE static void consider_yield(); 00056 00057 private: 00058 static DWORD WINAPI root_func(LPVOID data); 00059 static void init_pt_ptr_index(); 00060 00061 enum Status { 00062 S_new, 00063 S_start_called, 00064 S_running, 00065 S_finished 00066 }; 00067 00068 MutexWin32Impl _mutex; 00069 ConditionVarWin32Impl _cv; 00070 Thread *_parent_obj; 00071 HANDLE _thread; 00072 DWORD _thread_id; 00073 bool _joinable; 00074 Status _status; 00075 00076 static DWORD _pt_ptr_index; 00077 static bool _got_pt_ptr_index; 00078 }; 00079 00080 #include "threadWin32Impl.I" 00081 00082 #endif // THREAD_WIN32_IMPL 00083 00084 #endif