Correct JackPortAudioDriver::Open : special case for ASIO drivers.
[jack2.git] / macosx / JackMachThread.h
blob1aad4cc6b3c44bcc538a7116e708bd08391c022b
1 /*
2 Copyright (C) 2001 Paul Davis
3 Copyright (C) 2004-2008 Grame
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.
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.
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.
22 Copyright: Copyright 2002 Apple Computer, Inc. All rights reserved.
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.
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.
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.
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.
61 #ifndef __JackMachThread__
62 #define __JackMachThread__
64 #include <TargetConditionals.h>
66 #ifdef MY_TARGET_OS_IPHONE
67 typedef unsigned char Boolean;
68 #endif
71 #include "JackPosixThread.h"
72 #ifndef MY_TARGET_OS_IPHONE
73 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
74 #endif
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
82 #define THREAD_SET_PRIORITY 0
83 #define THREAD_SCHEDULED_PRIORITY 1
85 namespace Jack
88 /*!
89 \brief Darwin threads. Real-time threads are actually "time constraint" threads.
92 class SERVER_EXPORT JackMachThread : public JackPosixThread
95 private:
97 UInt64 fPeriod;
98 UInt64 fComputation;
99 UInt64 fConstraint;
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);
105 public:
107 JackMachThread(JackRunnableInterface* runnable, UInt64 period, UInt64 computation, UInt64 constraint)
108 : JackPosixThread(runnable), fPeriod(period), fComputation(computation), fConstraint(constraint)
111 JackMachThread(JackRunnableInterface* runnable, int cancellation = PTHREAD_CANCEL_ASYNCHRONOUS)
112 : JackPosixThread(runnable, cancellation), fPeriod(0), fComputation(0), fConstraint(0)
115 int Kill();
117 int AcquireRealTime(); // Used when called from another thread
118 int AcquireSelfRealTime(); // Used when called from thread itself
120 int AcquireRealTime(int priority); // Used when called from another thread
121 int AcquireSelfRealTime(int priority); // Used when called from thread itself
123 int DropRealTime(); // Used when called from another thread
124 int DropSelfRealTime(); // Used when called from thread itself
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);
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)
133 return JackMachThread::AcquireRealTimeImp(thread, period, computation, constraint);
135 static int DropRealTimeImp(jack_native_thread_t thread);
139 } // end of namespace
141 #endif