Jack2 1.9.10

JackMachThread.h

00001 /*
00002 Copyright (C) 2001 Paul Davis
00003 Copyright (C) 2004-2008 Grame
00004 
00005 This program is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU Lesser General Public License as published by
00007 the Free Software Foundation; either version 2.1 of the License, or
00008 (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 
00019 */
00020 
00021 /*
00022         Copyright:      Copyright 2002 Apple Computer, Inc. All rights reserved.
00023 
00024         Disclaimer:     IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
00025         ("Apple") in consideration of your agreement to the following terms, and your
00026         use, installation, modification or redistribution of this Apple software
00027         constitutes acceptance of these terms.  If you do not agree with these terms,
00028         please do not use, install, modify or redistribute this Apple software.
00029 
00030         In consideration of your agreement to abide by the following terms, and subject
00031         to these terms, Apple grants you a personal, non-exclusive license, under Apple
00032         copyrights in this original Apple software (the "Apple Software"), to use,
00033         reproduce, modify and redistribute the Apple Software, with or without
00034         modifications, in source and/or binary forms; provided that if you redistribute
00035         the Apple Software in its entirety and without modifications, you must retain
00036         this notice and the following text and disclaimers in all such redistributions of
00037         the Apple Software.  Neither the name, trademarks, service marks or logos of
00038         Apple Computer, Inc. may be used to endorse or promote products derived from the
00039         Apple Software without specific prior written permission from Apple.  Except as
00040         expressly stated in this notice, no other rights or licenses, express or implied,
00041         are granted by Apple herein, including but not limited to any patent rights that
00042         may be infringed by your derivative works or by other works in which the Apple
00043         Software may be incorporated.
00044 
00045         The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
00046         WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
00047         WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00048         PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
00049         COMBINATION WITH YOUR PRODUCTS.
00050 
00051         IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
00052         CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00053         GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00054         ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
00055         OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
00056         (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
00057         ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00058 */
00059 
00060 
00061 #ifndef __JackMachThread__
00062 #define __JackMachThread__
00063 
00064 #include <TargetConditionals.h>
00065 
00066 #ifdef MY_TARGET_OS_IPHONE
00067 typedef unsigned char Boolean;
00068 #endif
00069 
00070 
00071 #include "JackPosixThread.h"
00072 #ifndef MY_TARGET_OS_IPHONE
00073 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
00074 #endif
00075 
00076 #include <mach/thread_policy.h>
00077 #include <mach/thread_act.h>
00078 #ifndef MY_TARGET_OS_IPHONE
00079 #include <CoreAudio/HostTime.h>
00080 #endif
00081 
00082 #define THREAD_SET_PRIORITY         0
00083 #define THREAD_SCHEDULED_PRIORITY   1
00084 
00085 namespace Jack
00086 {
00087 
00092 class SERVER_EXPORT JackMachThread : public JackPosixThread
00093 {
00094 
00095     private:
00096 
00097         UInt64 fPeriod;
00098         UInt64 fComputation;
00099         UInt64 fConstraint;
00100 
00101         static UInt32 GetThreadSetPriority(jack_native_thread_t thread);
00102         static UInt32 GetThreadScheduledPriority(jack_native_thread_t thread);
00103         static UInt32 GetThreadPriority(jack_native_thread_t thread, int inWhichPriority);
00104 
00105     public:
00106 
00107         JackMachThread(JackRunnableInterface* runnable, UInt64 period, UInt64 computation, UInt64 constraint)
00108                 : JackPosixThread(runnable), fPeriod(period), fComputation(computation), fConstraint(constraint)
00109         {}
00110 
00111         JackMachThread(JackRunnableInterface* runnable, int cancellation = PTHREAD_CANCEL_ASYNCHRONOUS)
00112                 : JackPosixThread(runnable, cancellation), fPeriod(0), fComputation(0), fConstraint(0)
00113         {}
00114 
00115         int Kill();
00116 
00117         int AcquireRealTime();                  // Used when called from another thread
00118         int AcquireSelfRealTime();              // Used when called from thread itself
00119 
00120         int AcquireRealTime(int priority);      // Used when called from another thread
00121         int AcquireSelfRealTime(int priority);  // Used when called from thread itself
00122 
00123         int DropRealTime();                     // Used when called from another thread
00124         int DropSelfRealTime();                 // Used when called from thread itself
00125 
00126         void SetParams(UInt64 period, UInt64 computation, UInt64 constraint);
00127         static int GetParams(jack_native_thread_t thread, UInt64* period, UInt64* computation, UInt64* constraint);
00128         static int SetThreadToPriority(jack_native_thread_t thread, UInt32 inPriority, Boolean inIsFixed, UInt64 period, UInt64 computation, UInt64 constraint);
00129 
00130         static int AcquireRealTimeImp(jack_native_thread_t thread, UInt64 period, UInt64 computation, UInt64 constraint);
00131         static int AcquireRealTimeImp(jack_native_thread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint)
00132                 {
00133             return JackMachThread::AcquireRealTimeImp(thread, period, computation, constraint);
00134         }
00135         static int DropRealTimeImp(jack_native_thread_t thread);
00136 
00137 };
00138 
00139 } // end of namespace
00140 
00141 #endif