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 "JackPosixThread.h"
65 #import <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
67 #include <mach/thread_policy.h>
68 #include <mach/thread_act.h>
69 #include <CoreAudio/HostTime.h>
71 #define THREAD_SET_PRIORITY 0
72 #define THREAD_SCHEDULED_PRIORITY 1
78 \brief Darwin threads. Real-time threads are actually "time constraint" threads.
81 class SERVER_EXPORT JackMachThread
: public JackPosixThread
90 static UInt32
GetThreadSetPriority(pthread_t thread
);
91 static UInt32
GetThreadScheduledPriority(pthread_t thread
);
92 static UInt32
GetThreadPriority(pthread_t thread
, int inWhichPriority
);
96 JackMachThread(JackRunnableInterface
* runnable
, UInt64 period
, UInt64 computation
, UInt64 constraint
)
97 : JackPosixThread(runnable
), fPeriod(period
), fComputation(computation
), fConstraint(constraint
)
100 JackMachThread(JackRunnableInterface
* runnable
, int cancellation
= PTHREAD_CANCEL_ASYNCHRONOUS
)
101 : JackPosixThread(runnable
, cancellation
), fPeriod(0), fComputation(0), fConstraint(0)
106 int AcquireRealTime(); // Used when called from another thread
107 int AcquireSelfRealTime(); // Used when called from thread itself
109 int AcquireRealTime(int priority
); // Used when called from another thread
110 int AcquireSelfRealTime(int priority
); // Used when called from thread itself
112 int DropRealTime(); // Used when called from another thread
113 int DropSelfRealTime(); // Used when called from thread itself
115 void SetParams(UInt64 period
, UInt64 computation
, UInt64 constraint
);
116 static int GetParams(pthread_t thread
, UInt64
* period
, UInt64
* computation
, UInt64
* constraint
);
117 static int SetThreadToPriority(pthread_t thread
, UInt32 inPriority
, Boolean inIsFixed
, UInt64 period
, UInt64 computation
, UInt64 constraint
);
119 static int AcquireRealTimeImp(pthread_t thread
, UInt64 period
, UInt64 computation
, UInt64 constraint
);
120 static int AcquireRealTimeImp(pthread_t thread
, int priority
, UInt64 period
, UInt64 computation
, UInt64 constraint
)
122 return JackMachThread::AcquireRealTimeImp(thread
, period
, computation
, constraint
);
124 static int DropRealTimeImp(pthread_t thread
);
127 } // end of namespace