• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Core Audio thread priority
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Core Audio thread priority


  • Subject: Re: Core Audio thread priority
  • From: Paul Davis <email@hidden>
  • Date: Thu, 14 Oct 2010 23:34:27 -0400

On Thu, Oct 14, 2010 at 11:31 PM, Paul Davis <email@hidden> wrote:
> On Thu, Oct 14, 2010 at 11:27 PM, B.J. Buchalter <email@hidden> wrote:
>>
>> On Oct 14, 2010, at 11:10 PM, Paul Davis wrote:
>>
>>> thankfully, OS X makes this vastly simpler than most pthread-based
>>> systems. the jack code to do this is 1 line:
>>>
>>>       setThreadToPriority(thread, 96, TRUE, 10000000);
>>
>> Actually, that is a call to something that you have implemented in Jack.
>
> actually, no. this is an existing Mach or CoreFoobar call, AFAIK.
> Stephane can comment (and probably will).

meh, ran find(1) at the wrong level.  sorry.

setThreadToPriority comes from an apple utility library, licensed
using their "as-is" license.

the whole function looks like:

static inline void
setThreadToPriority(pthread_t inThread, UInt32 inPriority, Boolean inIsFixed,
		    UInt64 inHALIOProcCycleDurationInNanoseconds)
{
	if (inPriority == 96)
	{
            // REAL-TIME / TIME-CONSTRAINT THREAD
            thread_time_constraint_policy_data_t	theTCPolicy;
            UInt64					theComputeQuanta;
            UInt64					thePeriod;
            UInt64					thePeriodNanos;

            thePeriodNanos = inHALIOProcCycleDurationInNanoseconds;
            theComputeQuanta = AudioConvertNanosToHostTime (
thePeriodNanos * 0.15 );
            thePeriod = AudioConvertNanosToHostTime (thePeriodNanos);

            theTCPolicy.period = thePeriod;
            theTCPolicy.computation = theComputeQuanta;
            theTCPolicy.constraint = thePeriod;
            theTCPolicy.preemptible = true;
            thread_policy_set (pthread_mach_thread_np(inThread),
			       THREAD_TIME_CONSTRAINT_POLICY,
			       (thread_policy_t)&theTCPolicy,
			       THREAD_TIME_CONSTRAINT_POLICY_COUNT);
	} else {
            // OTHER THREADS
            thread_extended_policy_data_t		theFixedPolicy;
            thread_precedence_policy_data_t		thePrecedencePolicy;
            SInt32					relativePriority;

            // [1] SET FIXED / NOT FIXED
            theFixedPolicy.timeshare = !inIsFixed;
            thread_policy_set (pthread_mach_thread_np(inThread),
			       THREAD_EXTENDED_POLICY,
			       (thread_policy_t)&theFixedPolicy,
			       THREAD_EXTENDED_POLICY_COUNT);

            // [2] SET PRECEDENCE N.B.: We expect that if thread A
            // created thread B, and the program wishes to change the
            // priority of thread B, then the call to change the
            // priority of thread B must be made by thread A.  This
            // assumption allows us to use pthread_self() to correctly
            // calculate the priority of the feeder thread (since
            // precedency policy's importance is relative to the
            // spawning thread's priority.)
            relativePriority = inPriority -
		    getThreadSetPriority (pthread_self());

            thePrecedencePolicy.importance = relativePriority;
            thread_policy_set (pthread_mach_thread_np(inThread),
			       THREAD_PRECEDENCE_POLICY,
			       (thread_policy_t)&thePrecedencePolicy,
			       THREAD_PRECEDENCE_POLICY_COUNT);
	}
}


>
> --p
>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Core Audio thread priority
      • From: Paul Davis <email@hidden>
References: 
 >Core Audio thread priority (From: Evan Olcott <email@hidden>)
 >Re: Core Audio thread priority (From: Paul Davis <email@hidden>)
 >Re: Core Audio thread priority (From: "B.J. Buchalter" <email@hidden>)
 >Re: Core Audio thread priority (From: Paul Davis <email@hidden>)

  • Prev by Date: Re: Core Audio thread priority
  • Next by Date: Re: Core Audio thread priority
  • Previous by thread: Re: Core Audio thread priority
  • Next by thread: Re: Core Audio thread priority
  • Index(es):
    • Date
    • Thread