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.

124 lines
3.3KB

  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. /*!
  40. \brief The thread base class.
  41. */
  42. namespace detail
  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();
  74. int AcquireRealTime(int priority);
  75. int DropRealTime();
  76. pthread_t GetThreadID();
  77. static int AcquireRealTimeImp(pthread_t thread, int priority);
  78. static int AcquireRealTimeImp(pthread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint);
  79. static int DropRealTimeImp(pthread_t thread);
  80. static int StartImp(pthread_t* thread, int priority, int realtime, void*(*start_routine)(void*), void* arg);
  81. static int StopImp(pthread_t thread);
  82. static int KillImp(pthread_t thread);
  83. };
  84. }
  85. } // end of namespace
  86. bool jack_tls_allocate_key(jack_tls_key *key_ptr);
  87. bool jack_tls_free_key(jack_tls_key key);
  88. bool jack_tls_set(jack_tls_key key, void *data_ptr);
  89. void *jack_tls_get(jack_tls_key key);
  90. #endif