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.

115 lines
2.7KB

  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. #ifdef WIN32
  19. #include <windows.h>
  20. typedef HANDLE pthread_t;
  21. typedef ULONGLONG UInt64;
  22. #else
  23. #include <pthread.h>
  24. typedef unsigned long long UInt64;
  25. #endif
  26. namespace Jack
  27. {
  28. /*!
  29. \brief The base class for runnable objects, that have an <B> Init </B> and <B> Execute </B> method to be called in a thread.
  30. */
  31. class JackRunnableInterface
  32. {
  33. public:
  34. JackRunnableInterface()
  35. {}
  36. virtual ~JackRunnableInterface()
  37. {}
  38. virtual bool Init() /*! Called once when the thread is started */
  39. {
  40. return true;
  41. }
  42. virtual bool Execute() = 0; /*! Must be implemented by subclasses */
  43. };
  44. /*!
  45. \brief The thread base class.
  46. */
  47. namespace detail
  48. {
  49. class JackThread
  50. {
  51. public:
  52. enum kThreadState {kIdle, kStarting, kIniting, kRunning};
  53. protected:
  54. JackRunnableInterface* fRunnable;
  55. int fPriority;
  56. bool fRealTime;
  57. volatile kThreadState fStatus;
  58. int fCancellation;
  59. public:
  60. JackThread(JackRunnableInterface* runnable, int priority, bool real_time, int cancellation):
  61. fRunnable(runnable), fPriority(priority), fRealTime(real_time), fStatus(kIdle), fCancellation(cancellation)
  62. {}
  63. kThreadState GetStatus()
  64. {
  65. return fStatus;
  66. }
  67. void SetStatus(kThreadState status)
  68. {
  69. fStatus = status;
  70. }
  71. void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX...
  72. {}
  73. };
  74. }
  75. } // end of namespace
  76. #if defined(WIN32)
  77. typedef DWORD jack_tls_key;
  78. #else
  79. typedef pthread_key_t jack_tls_key;
  80. #endif
  81. bool jack_tls_allocate_key(jack_tls_key *key_ptr);
  82. bool jack_tls_free_key(jack_tls_key key);
  83. bool jack_tls_set(jack_tls_key key, void *data_ptr);
  84. void *jack_tls_get(jack_tls_key key);
  85. #endif