threadLinuxImpl.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Filename: threadLinuxImpl.h
  2. // Created by: drose (28Mar06)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef THREADLINUXIMPL_H
  19. #define THREADLINUXIMPL_H
  20. #include "pandabase.h"
  21. #include "selectThreadImpl.h"
  22. #ifdef THREAD_LINUX_IMPL
  23. #include "pnotify.h"
  24. #include "threadPriority.h"
  25. #include "mutexLinuxImpl.h"
  26. #include "conditionVarLinuxImpl.h"
  27. class Thread;
  28. ////////////////////////////////////////////////////////////////////
  29. // Class : ThreadLinuxImpl
  30. // Description : Uses low-level Linux-specific calls to implement
  31. // threads.
  32. ////////////////////////////////////////////////////////////////////
  33. class EXPCL_PANDA ThreadLinuxImpl {
  34. public:
  35. INLINE ThreadLinuxImpl(Thread *parent_obj);
  36. ~ThreadLinuxImpl();
  37. bool start(ThreadPriority priority, bool global, bool joinable);
  38. void interrupt();
  39. void join();
  40. INLINE static void prepare_for_exit();
  41. static Thread *get_current_thread();
  42. static void bind_thread(Thread *thread);
  43. INLINE static bool is_threading_supported();
  44. INLINE static void sleep(double seconds);
  45. private:
  46. static int root_func(void *data);
  47. enum Status {
  48. S_new,
  49. S_start_called,
  50. S_running,
  51. S_finished
  52. };
  53. MutexLinuxImpl _mutex;
  54. ConditionVarLinuxImpl _cv;
  55. Thread *_parent_obj;
  56. int _thread;
  57. bool _joinable;
  58. Status _status;
  59. unsigned char *_stack;
  60. // per-thread data.
  61. typedef pmap<pid_t, Thread *> ThreadPointers;
  62. static ThreadPointers _thread_pointers;
  63. static MutexLinuxImpl _thread_pointers_lock;
  64. static bool _got_main_thread_pointer;
  65. };
  66. #include "threadLinuxImpl.I"
  67. #endif // THREAD_LINUX_IMPL
  68. #endif