Panda3D
 All Classes Functions Variables Enumerations
threadPosixImpl.h
1 // Filename: threadPosixImpl.h
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 #ifndef THREADPOSIXIMPL_H
16 #define THREADPOSIXIMPL_H
17 
18 #include "pandabase.h"
19 #include "selectThreadImpl.h"
20 
21 #ifdef THREAD_POSIX_IMPL
22 
23 #include "pnotify.h"
24 #include "threadPriority.h"
25 #include "mutexPosixImpl.h"
26 
27 #include <pthread.h>
28 
29 class Thread;
30 
31 ////////////////////////////////////////////////////////////////////
32 // Class : ThreadPosixImpl
33 // Description : Uses Posix threads to implement a thread.
34 ////////////////////////////////////////////////////////////////////
35 class EXPCL_PANDA_PIPELINE ThreadPosixImpl {
36 public:
37  INLINE ThreadPosixImpl(Thread *parent_obj);
38  ~ThreadPosixImpl();
39 
40  void setup_main_thread();
41  bool start(ThreadPriority priority, bool joinable);
42  void join();
43  INLINE void preempt();
44 
45  string get_unique_id() const;
46 
47  INLINE static void prepare_for_exit();
48 
49  INLINE static Thread *get_current_thread();
50  INLINE static void bind_thread(Thread *thread);
51  INLINE static bool is_threading_supported();
52  INLINE static bool is_true_threads();
53  INLINE static bool is_simple_threads();
54  INLINE static void sleep(double seconds);
55  INLINE static void yield();
56  INLINE static void consider_yield();
57 
58 private:
59  static void *root_func(void *data);
60  static void init_pt_ptr_index();
61 
62  // There appears to be a name collision with the word "Status".
63  enum PStatus {
64  S_new,
65  S_start_called,
66  S_running,
67  S_finished,
68  };
69 
70  MutexPosixImpl _mutex;
71  Thread *_parent_obj;
72  pthread_t _thread;
73  bool _joinable;
74  bool _detached;
75  PStatus _status;
76 
77  static pthread_key_t _pt_ptr_index;
78  static bool _got_pt_ptr_index;
79 };
80 
81 #include "threadPosixImpl.I"
82 
83 #endif // THREAD_POSIX_IMPL
84 
85 #endif
A thread; that is, a lightweight process.
Definition: thread.h:51