Panda3D
threadPosixImpl.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file threadPosixImpl.h
10  * @author drose
11  * @date 2006-02-09
12  */
13 
14 #ifndef THREADPOSIXIMPL_H
15 #define THREADPOSIXIMPL_H
16 
17 #include "pandabase.h"
18 #include "selectThreadImpl.h"
19 
20 #ifdef THREAD_POSIX_IMPL
21 
22 #include "pnotify.h"
23 #include "threadPriority.h"
24 #include "mutexPosixImpl.h"
25 
26 #include <pthread.h>
27 
28 #ifdef ANDROID
29 typedef struct _JNIEnv JNIEnv;
30 #endif
31 
32 class Thread;
33 
34 /**
35  * Uses Posix threads to implement a thread.
36  */
37 class EXPCL_PANDA_PIPELINE ThreadPosixImpl {
38 public:
39  INLINE ThreadPosixImpl(Thread *parent_obj);
40  ~ThreadPosixImpl();
41 
42  void setup_main_thread();
43  bool start(ThreadPriority priority, bool joinable);
44  void join();
45  INLINE void preempt();
46 
47  std::string get_unique_id() const;
48 
49  INLINE static void prepare_for_exit();
50 
51  INLINE static Thread *get_current_thread();
52  INLINE static void bind_thread(Thread *thread);
53  INLINE static bool is_threading_supported();
54  INLINE static bool is_true_threads();
55  INLINE static bool is_simple_threads();
56  INLINE static void sleep(double seconds);
57  INLINE static void yield();
58  INLINE static void consider_yield();
59 
60 #ifdef ANDROID
61  INLINE JNIEnv *get_jni_env() const;
62  bool attach_java_vm();
63  static void bind_java_thread();
64 #endif
65 
66 private:
67  static void *root_func(void *data);
68  static void init_pt_ptr_index();
69 
70  // There appears to be a name collision with the word "Status".
71  enum PStatus {
72  S_new,
73  S_start_called,
74  S_running,
75  S_finished,
76  };
77 
78  MutexPosixImpl _mutex;
79  Thread *_parent_obj;
80  pthread_t _thread;
81  bool _joinable;
82  bool _detached;
83  PStatus _status;
84 
85 #ifdef ANDROID
86  JNIEnv *_jni_env;
87 #endif
88 
89  static pthread_key_t _pt_ptr_index;
90  static bool _got_pt_ptr_index;
91 };
92 
93 #include "threadPosixImpl.I"
94 
95 #endif // THREAD_POSIX_IMPL
96 
97 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A thread; that is, a lightweight process.
Definition: thread.h:46
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.