Panda3D
threadWin32Impl.h
1 // Filename: threadWin32Impl.h
2 // Created by: drose (07Feb06)
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 #ifndef THREADWIN32IMPL_H
16 #define THREADWIN32IMPL_H
17 
18 #include "pandabase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef THREAD_WIN32_IMPL
22 
23 #include "pnotify.h"
24 #include "threadPriority.h"
25 #include "mutexWin32Impl.h"
26 #include "conditionVarWin32Impl.h"
27 
28 class Thread;
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : ThreadWin32Impl
32 // Description : Uses native Windows calls to implement a thread.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_PIPELINE ThreadWin32Impl {
35 public:
36  INLINE ThreadWin32Impl(Thread *parent_obj);
37  ~ThreadWin32Impl();
38 
39  void setup_main_thread();
40  bool start(ThreadPriority priority, bool joinable);
41  void join();
42  INLINE void preempt();
43 
44  string get_unique_id() const;
45 
46  INLINE static void prepare_for_exit();
47 
48  INLINE static Thread *get_current_thread();
49  INLINE static void bind_thread(Thread *thread);
50  INLINE static bool is_threading_supported();
51  INLINE static bool is_true_threads();
52  INLINE static bool is_simple_threads();
53  INLINE static void sleep(double seconds);
54  INLINE static void yield();
55  INLINE static void consider_yield();
56 
57 private:
58  static DWORD WINAPI root_func(LPVOID data);
59  static void init_pt_ptr_index();
60 
61  enum Status {
62  S_new,
63  S_start_called,
64  S_running,
65  S_finished
66  };
67 
68  MutexWin32Impl _mutex;
69  ConditionVarWin32Impl _cv;
70  Thread *_parent_obj;
71  HANDLE _thread;
72  DWORD _thread_id;
73  bool _joinable;
74  Status _status;
75 
76  static DWORD _pt_ptr_index;
77  static bool _got_pt_ptr_index;
78 };
79 
80 #include "threadWin32Impl.I"
81 
82 #endif // THREAD_WIN32_IMPL
83 
84 #endif
A thread; that is, a lightweight process.
Definition: thread.h:51