Jack2 1.9.6

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 "JackPosixThread.h"
00065 #import <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacTypes.h>
00066 
00067 #include <mach/thread_policy.h>
00068 #include <mach/thread_act.h>
00069 #include <CoreAudio/HostTime.h>
00070 
00071 #define THREAD_SET_PRIORITY         0
00072 #define THREAD_SCHEDULED_PRIORITY   1
00073 
00074 namespace Jack
00075 {
00076 
00081 class SERVER_EXPORT JackMachThread : public JackPosixThread
00082 {
00083 
00084     private:
00085 
00086         UInt64 fPeriod;
00087         UInt64 fComputation;
00088         UInt64 fConstraint;
00089 
00090         static UInt32 GetThreadSetPriority(pthread_t thread);
00091         static UInt32 GetThreadScheduledPriority(pthread_t thread);
00092         static UInt32 GetThreadPriority(pthread_t thread, int inWhichPriority);
00093 
00094     public:
00095 
00096         JackMachThread(JackRunnableInterface* runnable, UInt64 period, UInt64 computation, UInt64 constraint)
00097                 : JackPosixThread(runnable), fPeriod(period), fComputation(computation), fConstraint(constraint)
00098         {}
00099 
00100         JackMachThread(JackRunnableInterface* runnable, int cancellation = PTHREAD_CANCEL_ASYNCHRONOUS)
00101                 : JackPosixThread(runnable, cancellation), fPeriod(0), fComputation(0), fConstraint(0)
00102         {}
00103 
00104         int Kill();
00105 
00106         int AcquireRealTime();                  // Used when called from another thread
00107         int AcquireSelfRealTime();              // Used when called from thread itself
00108         
00109         int AcquireRealTime(int priority);      // Used when called from another thread
00110         int AcquireSelfRealTime(int priority);  // Used when called from thread itself
00111         
00112         int DropRealTime();                     // Used when called from another thread
00113         int DropSelfRealTime();                 // Used when called from thread itself
00114         
00115         void SetParams(UInt64 period, UInt64 computation, UInt64 constraint);
00116         static int GetParams(pthread_t thread, UInt64* period, UInt64* computation, UInt64* constraint);
00117         static int SetThreadToPriority(pthread_t thread, UInt32 inPriority, Boolean inIsFixed, UInt64 period, UInt64 computation, UInt64 constraint);
00118 
00119         static int AcquireRealTimeImp(pthread_t thread, UInt64 period, UInt64 computation, UInt64 constraint);
00120         static int AcquireRealTimeImp(pthread_t thread, int priority, UInt64 period, UInt64 computation, UInt64 constraint)
00121                 { 
00122             return JackMachThread::AcquireRealTimeImp(thread, period, computation, constraint); 
00123         }
00124         static int DropRealTimeImp(pthread_t thread);
00125 };
00126 
00127 } // end of namespace
00128 
00129 #endif