Jack2 1.9.12

JackMachThread.h
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 */
20
21 /*
22 Copyright: Copyright 2002 Apple Computer, Inc. All rights reserved.
23
24 Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
25 ("Apple") in consideration of your agreement to the following terms, and your
26 use, installation, modification or redistribution of this Apple software
27 constitutes acceptance of these terms. If you do not agree with these terms,
28 please do not use, install, modify or redistribute this Apple software.
29
30 In consideration of your agreement to abide by the following terms, and subject
31 to these terms, Apple grants you a personal, non-exclusive license, under Apple
32 copyrights in this original Apple software (the "Apple Software"), to use,
33 reproduce, modify and redistribute the Apple Software, with or without
34 modifications, in source and/or binary forms; provided that if you redistribute
35 the Apple Software in its entirety and without modifications, you must retain
36 this notice and the following text and disclaimers in all such redistributions of
37 the Apple Software. Neither the name, trademarks, service marks or logos of
38 Apple Computer, Inc. may be used to endorse or promote products derived from the
39 Apple Software without specific prior written permission from Apple. Except as
40 expressly stated in this notice, no other rights or licenses, express or implied,
41 are granted by Apple herein, including but not limited to any patent rights that
42 may be infringed by your derivative works or by other works in which the Apple
43 Software may be incorporated.
44
45 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
46 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
47 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
49 COMBINATION WITH YOUR PRODUCTS.
50
51 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
52 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
53 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
55 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
56 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
57 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
58 */
59
60
61 #ifndef __JackMachThread__
62 #define __JackMachThread__
63
64 #include <TargetConditionals.h>
65
66 #ifdef MY_TARGET_OS_IPHONE
67 typedef unsigned char Boolean;
68 #endif
69
70
71 #include "JackPosixThread.h"
72 #ifndef MY_TARGET_OS_IPHONE
73 #include <MacTypes.h>
74 #endif
75
76 #include <mach/thread_policy.h>
77 #include <mach/thread_act.h>
78 #ifndef MY_TARGET_OS_IPHONE
79 #include <CoreAudio/HostTime.h>
80 #endif
81
82 #define THREAD_SET_PRIORITY 0
83 #define THREAD_SCHEDULED_PRIORITY 1
84
85 namespace Jack
86 {
87
92 class SERVER_EXPORT JackMachThread : public JackPosixThread
93 {
94
95 private:
96
97 UInt64 fPeriod;
98 UInt64 fComputation;
99 UInt64 fConstraint;
100
101 static UInt32 GetThreadSetPriority(jack_native_thread_t thread);
102 static UInt32 GetThreadScheduledPriority(jack_native_thread_t thread);
103 static UInt32 GetThreadPriority(jack_native_thread_t thread, int inWhichPriority);
104
105 public:
106
107 JackMachThread(JackRunnableInterface* runnable, UInt64 period, UInt64 computation, UInt64 constraint)
108 : JackPosixThread(runnable), fPeriod(period), fComputation(computation), fConstraint(constraint)
109 {}
110
111 JackMachThread(JackRunnableInterface* runnable, int cancellation = PTHREAD_CANCEL_ASYNCHRONOUS)
112 : JackPosixThread(runnable, cancellation), fPeriod(0), fComputation(0), fConstraint(0)
113 {}
114
115 int Kill();
116
117 int AcquireRealTime(); // Used when called from another thread
118 int AcquireSelfRealTime(); // Used when called from thread itself
119
120 int AcquireRealTime(int priority); // Used when called from another thread
121 int AcquireSelfRealTime(int priority); // Used when called from thread itself
122
123 int DropRealTime(); // Used when called from another thread
124 int DropSelfRealTime(); // Used when called from thread itself
125
126 void SetParams(UInt64 period, UInt64 computation, UInt64 constraint);
127 static int GetParams(jack_native_thread_t thread, UInt64* period, UInt64* computation, UInt64* constraint);
128 static int SetThreadToPriority(jack_native_thread_t thread, UInt32 inPriority, Boolean inIsFixed, UInt64 period, UInt64 computation, UInt64 constraint);
129
130 static int AcquireRealTimeImp(jack_native_thread_t thread, UInt64 period, UInt64 computation, UInt64 constraint);
131 static int AcquireRealTimeImp(jack_native_thread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint)
132 {
133 return JackMachThread::AcquireRealTimeImp(thread, period, computation, constraint);
134 }
135 static int DropRealTimeImp(jack_native_thread_t thread);
136
137 };
138
139 } // end of namespace
140
141 #endif
Jack::JackPosixThread
The POSIX thread base class.
Definition: JackPosixThread.h:38
Jack::JackRunnableInterface
The base class for runnable objects, that have an Init and Execute method to be called in a threa...
Definition: JackThread.h:34
Jack::JackMachThread
Darwin threads. Real-time threads are actually "time constraint" threads.
Definition: JackMachThread.h:92