jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
3.8KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #ifndef __JackThread__
  17. #define __JackThread__
  18. #include "JackCompilerDeps.h"
  19. #include "JackTypes.h"
  20. namespace Jack
  21. {
  22. /*!
  23. \brief The base class for runnable objects, that have an <B> Init </B> and <B> Execute </B> method to be called in a thread.
  24. */
  25. class JackRunnableInterface
  26. {
  27. protected:
  28. JackRunnableInterface()
  29. {}
  30. virtual ~JackRunnableInterface()
  31. {}
  32. public:
  33. virtual bool Init() /*! Called once when the thread is started */
  34. {
  35. return true;
  36. }
  37. virtual bool Execute() = 0; /*! Must be implemented by subclasses */
  38. };
  39. namespace detail
  40. {
  41. /*!
  42. \brief The thread base class.
  43. */
  44. class SERVER_EXPORT JackThreadInterface
  45. {
  46. public:
  47. enum kThreadState {kIdle, kStarting, kIniting, kRunning};
  48. protected:
  49. JackRunnableInterface* fRunnable;
  50. int fPriority;
  51. bool fRealTime;
  52. volatile kThreadState fStatus;
  53. int fCancellation;
  54. public:
  55. JackThreadInterface(JackRunnableInterface* runnable, int priority, bool real_time, int cancellation):
  56. fRunnable(runnable), fPriority(priority), fRealTime(real_time), fStatus(kIdle), fCancellation(cancellation)
  57. {}
  58. kThreadState GetStatus()
  59. {
  60. return fStatus;
  61. }
  62. void SetStatus(kThreadState status)
  63. {
  64. fStatus = status;
  65. }
  66. void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX...
  67. {}
  68. int Start();
  69. int StartSync();
  70. int Kill();
  71. int Stop();
  72. void Terminate();
  73. int AcquireRealTime(); // Used when called from another thread
  74. int AcquireSelfRealTime(); // Used when called from thread itself
  75. int AcquireRealTime(int priority); // Used when called from another thread
  76. int AcquireSelfRealTime(int priority); // Used when called from thread itself
  77. int DropRealTime(); // Used when called from another thread
  78. int DropSelfRealTime(); // Used when called from thread itself
  79. jack_native_thread_t GetThreadID();
  80. bool IsThread();
  81. static int AcquireRealTimeImp(jack_native_thread_t thread, int priority);
  82. static int AcquireRealTimeImp(jack_native_thread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint);
  83. static int DropRealTimeImp(jack_native_thread_t thread);
  84. static int StartImp(jack_native_thread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg);
  85. static int StopImp(jack_native_thread_t thread);
  86. static int KillImp(jack_native_thread_t thread);
  87. };
  88. }
  89. } // end of namespace
  90. bool jack_get_thread_realtime_priority_range(int * min_ptr, int * max_ptr);
  91. bool jack_tls_allocate_key(jack_tls_key *key_ptr);
  92. bool jack_tls_free_key(jack_tls_key key);
  93. bool jack_tls_set(jack_tls_key key, void *data_ptr);
  94. void *jack_tls_get(jack_tls_key key);
  95. #endif