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.

120 lines
5.0KB

  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. /*
  17. Copyright: © Copyright 2002 Apple Computer, Inc. All rights reserved.
  18. Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
  19. ("Apple") in consideration of your agreement to the following terms, and your
  20. use, installation, modification or redistribution of this Apple software
  21. constitutes acceptance of these terms. If you do not agree with these terms,
  22. please do not use, install, modify or redistribute this Apple software.
  23. In consideration of your agreement to abide by the following terms, and subject
  24. to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
  25. copyrights in this original Apple software (the "Apple Software"), to use,
  26. reproduce, modify and redistribute the Apple Software, with or without
  27. modifications, in source and/or binary forms; provided that if you redistribute
  28. the Apple Software in its entirety and without modifications, you must retain
  29. this notice and the following text and disclaimers in all such redistributions of
  30. the Apple Software. Neither the name, trademarks, service marks or logos of
  31. Apple Computer, Inc. may be used to endorse or promote products derived from the
  32. Apple Software without specific prior written permission from Apple. Except as
  33. expressly stated in this notice, no other rights or licenses, express or implied,
  34. are granted by Apple herein, including but not limited to any patent rights that
  35. may be infringed by your derivative works or by other works in which the Apple
  36. Software may be incorporated.
  37. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
  38. WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  39. WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  40. PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  41. COMBINATION WITH YOUR PRODUCTS.
  42. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  43. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  44. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45. ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  46. OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  47. (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  48. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. */
  50. #ifndef __JackMachThread__
  51. #define __JackMachThread__
  52. #include "JackPosixThread.h"
  53. #import <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
  54. #include <mach/thread_policy.h>
  55. #include <mach/thread_act.h>
  56. #include <CoreAudio/HostTime.h>
  57. #define THREAD_SET_PRIORITY 0
  58. #define THREAD_SCHEDULED_PRIORITY 1
  59. namespace Jack
  60. {
  61. /*!
  62. \brief Darwin threads. Real-time threads are actually "time constraint" threads.
  63. */
  64. class SERVER_EXPORT JackMachThread : public JackPosixThread
  65. {
  66. private:
  67. UInt64 fPeriod;
  68. UInt64 fComputation;
  69. UInt64 fConstraint;
  70. static UInt32 GetThreadSetPriority(pthread_t thread);
  71. static UInt32 GetThreadScheduledPriority(pthread_t thread);
  72. static UInt32 GetThreadPriority(pthread_t thread, int inWhichPriority);
  73. public:
  74. JackMachThread(JackRunnableInterface* runnable, UInt64 period, UInt64 computation, UInt64 constraint)
  75. : JackPosixThread(runnable), fPeriod(period), fComputation(computation), fConstraint(constraint)
  76. {}
  77. JackMachThread(JackRunnableInterface* runnable, int cancellation = PTHREAD_CANCEL_ASYNCHRONOUS)
  78. : JackPosixThread(runnable, cancellation), fPeriod(0), fComputation(0), fConstraint(0)
  79. {}
  80. int Kill();
  81. int AcquireRealTime();
  82. int AcquireRealTime(int priority);
  83. int DropRealTime();
  84. void SetParams(UInt64 period, UInt64 computation, UInt64 constraint);
  85. static int GetParams(UInt64* period, UInt64* computation, UInt64* constraint);
  86. static int SetThreadToPriority(pthread_t thread, UInt32 inPriority, Boolean inIsFixed, UInt64 period, UInt64 computation, UInt64 constraint);
  87. static int AcquireRealTimeImp(pthread_t thread, UInt64 period, UInt64 computation, UInt64 constraint);
  88. static int DropRealTimeImp(pthread_t thread);
  89. };
  90. } // end of namespace
  91. #endif