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.

103 lines
2.5KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2006 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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. class JackThread
  48. {
  49. protected:
  50. JackRunnableInterface* fRunnable;
  51. int fPriority;
  52. bool fRealTime;
  53. volatile bool fRunning;
  54. int fCancellation;
  55. public:
  56. JackThread(JackRunnableInterface* runnable, int priority, bool real_time, int cancellation):
  57. fRunnable(runnable), fPriority(priority), fRealTime(real_time), fRunning(false), fCancellation(cancellation)
  58. {}
  59. virtual ~JackThread()
  60. {}
  61. virtual int Start() = 0;
  62. virtual int StartSync() = 0;
  63. virtual int Kill() = 0;
  64. virtual int Stop() = 0;
  65. virtual int AcquireRealTime() = 0;
  66. virtual int AcquireRealTime(int priority) = 0;
  67. virtual int DropRealTime() = 0;
  68. virtual void SetParams(UInt64 period, UInt64 computation, UInt64 constraint) // Empty implementation, will only make sense on OSX...
  69. {}
  70. virtual pthread_t GetThreadID() = 0;
  71. bool IsRunning()
  72. {
  73. return fRunning;
  74. }
  75. };
  76. } // end of namespace
  77. #endif