这篇教程C++ thread_policy_set函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中thread_policy_set函数的典型用法代码示例。如果您正苦于以下问题:C++ thread_policy_set函数的具体用法?C++ thread_policy_set怎么用?C++ thread_policy_set使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了thread_policy_set函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: thread_setupstatic voidthread_setup(int tag) { kern_return_t ret; thread_extended_policy_data_t epolicy; thread_affinity_policy_data_t policy; if (!timeshare) { epolicy.timeshare = FALSE; ret = thread_policy_set( mach_thread_self(), THREAD_EXTENDED_POLICY, (thread_policy_t) &epolicy, THREAD_EXTENDED_POLICY_COUNT); if (ret != KERN_SUCCESS) printf("thread_policy_set(THREAD_EXTENDED_POLICY) returned %d/n", ret); } if (affinity) { policy.affinity_tag = tag; ret = thread_policy_set( mach_thread_self(), THREAD_AFFINITY_POLICY, (thread_policy_t) &policy, THREAD_AFFINITY_POLICY_COUNT); if (ret != KERN_SUCCESS) printf("thread_policy_set(THREAD_AFFINITY_POLICY) returned %d/n", ret); }}
开发者ID:JackieXie168,项目名称:xnu,代码行数:26,
示例2: SetPriority void SetPriority(UInt32 inPriority, bool inFixedPriority) { OSStatus result = noErr; mPriority = inPriority; mFixedPriority = inFixedPriority; if(mPThread != 0) { if (mFixedPriority) { thread_extended_policy_data_t theFixedPolicy; theFixedPolicy.timeshare = false; // set to true for a non-fixed thread result = thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); if (result) { printf("OpenALThread::SetPriority: failed to set the fixed-priority policy"); return; } } // We keep a reference to the spawning thread's priority around (initialized in the constructor), // and set the importance of the child thread relative to the spawning thread's priority. thread_precedence_policy_data_t thePrecedencePolicy; thePrecedencePolicy.importance = mPriority - mSpawningThreadPriority; result =thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); if (result) { printf("OpenALThread::SetPriority: failed to set the precedence policy"); return; } } }
开发者ID:melling,项目名称:Sierpinski,代码行数:29,
示例3: nacl_thread_niceint nacl_thread_nice(int nacl_nice) { kern_return_t kr; /* * Don't use mach_thread_self() because it requires a separate * mach_port_deallocate() system call to release it. Instead, rely on * pthread's cached copy of the port. */ thread_act_t mthread = pthread_mach_thread_np(pthread_self()); switch (nacl_nice) { case NICE_REALTIME: { struct thread_time_constraint_policy tcpolicy; const int kPeriodInNanoseconds = 2902490; const float kDutyCycle = 0.5; const float kDutyMax = 0.85; tcpolicy.period = MyConvertToHostTime(kPeriodInNanoseconds); tcpolicy.computation = kDutyCycle * tcpolicy.period; tcpolicy.constraint = kDutyMax * tcpolicy.period; tcpolicy.preemptible = 1; /* Sadly it appears that a MacOS system can be locked up by too * many real-time threads. So use normal priority until we figure * out a way to control things globally. */ /* kr = thread_policy_set(mthread, THREAD_TIME_CONSTRAINT_POLICY, * (thread_policy_t)&tcpolicy, * THREAD_TIME_CONSTRAINT_POLICY_COUNT); */ kr = thread_policy_set(mthread, THREAD_PRECEDENCE_POLICY, (thread_policy_t)&tcpolicy, THREAD_PRECEDENCE_POLICY_COUNT); } break; case NICE_BACKGROUND: { struct thread_precedence_policy tppolicy; tppolicy.importance = 0; /* IDLE_PRI */ kr = thread_policy_set(mthread, THREAD_PRECEDENCE_POLICY, (thread_policy_t)&tppolicy, THREAD_PRECEDENCE_POLICY_COUNT); } break; case NICE_NORMAL: { struct thread_standard_policy tspolicy; kr = thread_policy_set(mthread, THREAD_STANDARD_POLICY, (thread_policy_t)&tspolicy, THREAD_STANDARD_POLICY_COUNT); } break; default: NaClLog(LOG_WARNING, "nacl_thread_nice() failed (bad nice value)./n"); return -1; break; } if (kr != KERN_SUCCESS) { NaClLog(LOG_WARNING, "nacl_thread_nice() failed./n"); return -1; } else { return 0; }}
开发者ID:mariospr,项目名称:chromium-browser,代码行数:60,
示例4: thread_policy_setvoid CAPThread::SetPriority(UInt32 inPriority, bool inFixedPriority){ mPriority = inPriority; mTimeConstraintSet = false; mFixedPriority = inFixedPriority;#if TARGET_OS_MAC if(mPThread != 0) { kern_return_t theError = 0; // set whether or not this is a fixed priority thread if (mFixedPriority) { thread_extended_policy_data_t theFixedPolicy = { false }; theError = thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); AssertNoKernelError(theError, "CAPThread::SetPriority: failed to set the fixed-priority policy"); } // set the thread's absolute priority which is relative to the priority on which thread_policy_set() is called UInt32 theCurrentThreadPriority = getScheduledPriority(pthread_self(), CAPTHREAD_SET_PRIORITY); thread_precedence_policy_data_t thePrecedencePolicy = { static_cast<integer_t>(mPriority - theCurrentThreadPriority) }; theError = thread_policy_set(pthread_mach_thread_np(mPThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); AssertNoKernelError(theError, "CAPThread::SetPriority: failed to set the precedence policy"); #if Log_SetPriority DebugMessageN4("CAPThread::SetPriority: requsted: %lu spawning: %lu current: %lu assigned: %d", mPriority, mSpawningThreadPriority, theCurrentThreadPriority, thePrecedencePolicy.importance); #endif } #elif TARGET_OS_WIN32 if(mThreadHandle != NULL) { SetThreadPriority(mThreadHandle, mPriority); }#endif}
开发者ID:cchaz003,项目名称:rivenx,代码行数:35,
示例5: SetThreadToPrioritystatic int SetThreadToPriority(pthread_t thread, UInt32 inPriority, Boolean inIsFixed, UInt64 period, UInt64 computation, UInt64 constraint){ if (inPriority == 96) { // REAL-TIME / TIME-CONSTRAINT THREAD thread_time_constraint_policy_data_t theTCPolicy; theTCPolicy.period = period; theTCPolicy.computation = computation; theTCPolicy.constraint = constraint; theTCPolicy.preemptible = true; kern_return_t res = thread_policy_set(pthread_mach_thread_np(thread), THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&theTCPolicy, THREAD_TIME_CONSTRAINT_POLICY_COUNT); return (res == KERN_SUCCESS) ? 0 : -1; } 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(thread), 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; kern_return_t res = thread_policy_set(pthread_mach_thread_np(thread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); return (res == KERN_SUCCESS) ? 0 : -1; }}
开发者ID:onukore,项目名称:radium,代码行数:35,
示例6: pthread_attr_initvoid FileReaderThread::StartFixedPriorityThread (){ pthread_attr_t theThreadAttrs; pthread_t pThread; OSStatus result = pthread_attr_init(&theThreadAttrs); THROW_RESULT("pthread_attr_init - Thread attributes could not be created.") result = pthread_attr_setdetachstate(&theThreadAttrs, PTHREAD_CREATE_DETACHED); THROW_RESULT("pthread_attr_setdetachstate - Thread attributes could not be detached.") result = pthread_create (&pThread, &theThreadAttrs, DiskReaderEntry, this); THROW_RESULT("pthread_create - Create and start the thread.") pthread_attr_destroy(&theThreadAttrs); // we've now created the thread and started it // we'll now set the priority of the thread to the nominated priority // and we'll also make the thread fixed thread_extended_policy_data_t theFixedPolicy; thread_precedence_policy_data_t thePrecedencePolicy; SInt32 relativePriority; // make thread fixed theFixedPolicy.timeshare = false; // set to true for a non-fixed thread result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); THROW_RESULT("thread_policy - Couldn't set thread as fixed priority.") // set priority // precedency policy's "importance" value is relative to spawning thread's priority relativePriority = mThreadPriority - FileReaderThread::GetThreadBasePriority (pthread_self()); thePrecedencePolicy.importance = relativePriority; result = thread_policy_set (pthread_mach_thread_np(pThread), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); THROW_RESULT("thread_policy - Couldn't set thread priority.")}
开发者ID:fruitsamples,项目名称:PublicUtility,代码行数:35,
示例7: RescheduleStdThread// Reschedules the indicated thread according to new parameters://// machThread The mach thread id. Pass 0 for the current thread.// newPriority The desired priority.// isTimeShare false for round robin (fixed) priority,// true for timeshare (normal) priority//// A standard new thread usually has a priority of 0 and uses the// timeshare scheduling scheme. Use pthread_mach_thread_np() to// to convert a pthread id to a mach thread idkern_return_t RescheduleStdThread( mach_port_t machThread, int newPriority, boolean_t isTimeshare ){ kern_return_t result = 0; thread_extended_policy_data_t timeShareData; thread_precedence_policy_data_t precedenceData; //Set up some variables that we need for the task precedenceData.importance = newPriority; timeShareData.timeshare = isTimeshare; if( 0 == machThread ) machThread = mach_thread_self(); //Set the scheduling flavor. We want to do this first, since doing so //can alter the priority result = thread_policy_set( machThread, THREAD_EXTENDED_POLICY, (integer_t*)&timeShareData, THREAD_EXTENDED_POLICY_COUNT ); if( 0 != result ) return result; //Now set the priority return thread_policy_set( machThread, THREAD_PRECEDENCE_POLICY, (integer_t*)&precedenceData, THREAD_PRECEDENCE_POLICY_COUNT );}
开发者ID:ELVIS-Project,项目名称:VISIntervalSonifier,代码行数:41,
示例8: Pt_Threadstatic void* Pt_Thread(void *p){ CFTimeInterval timerInterval; CFRunLoopTimerContext timerContext; CFRunLoopTimerRef timer; PtThreadParams *params = (PtThreadParams*)p; //CFTimeInterval timeout; /* raise the thread's priority */ kern_return_t error; thread_extended_policy_data_t extendedPolicy; thread_precedence_policy_data_t precedencePolicy; extendedPolicy.timeshare = 0; error = thread_policy_set(mach_thread_self(), THREAD_EXTENDED_POLICY, (thread_policy_t)&extendedPolicy, THREAD_EXTENDED_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread timeshare policy", error); } precedencePolicy.importance = THREAD_IMPORTANCE; error = thread_policy_set(mach_thread_self(), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&precedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread precedence policy", error); } /* set up the timer context */ timerContext.version = 0; timerContext.info = params; timerContext.retain = NULL; timerContext.release = NULL; timerContext.copyDescription = NULL; /* create a new timer */ timerInterval = (double)params->resolution / 1000.0; timer = CFRunLoopTimerCreate(NULL, startTime+timerInterval, timerInterval, 0, 0, Pt_CFTimerCallback, &timerContext); timerRunLoop = CFRunLoopGetCurrent(); CFRunLoopAddTimer(timerRunLoop, timer, CFSTR("PtTimeMode")); /* run until we're told to stop by Pt_Stop() */ CFRunLoopRunInMode(CFSTR("PtTimeMode"), LONG_TIME, false); CFRunLoopRemoveTimer(CFRunLoopGetCurrent(), timer, CFSTR("PtTimeMode")); CFRelease(timer); free(params); return NULL;}
开发者ID:AkiraShirase,项目名称:audacity,代码行数:53,
示例9: setAffinity /*! set affinity of the calling thread */ void setAffinity(ssize_t affinity) { thread_affinity_policy ap; ap.affinity_tag = affinity; if (thread_policy_set(mach_thread_self(),THREAD_AFFINITY_POLICY,(thread_policy_t)&ap,THREAD_AFFINITY_POLICY_COUNT) != KERN_SUCCESS) std::cerr << "Thread: cannot set affinity" << std::endl; }
开发者ID:utkarshayachit,项目名称:OSPRay,代码行数:8,
示例10: nanoseconds_to_absolutetimeIOWorkLoop *IOFWUserLocalIsochPort::createRealtimeThread(){ IOWorkLoop * workloop = IOWorkLoop::workLoop() ; if ( workloop ) { // Boost isoc workloop into realtime range thread_time_constraint_policy_data_t constraints; AbsoluteTime time; nanoseconds_to_absolutetime(625000, &time); constraints.period = AbsoluteTime_to_scalar(&time); nanoseconds_to_absolutetime(60000, &time); constraints.computation = AbsoluteTime_to_scalar(&time); nanoseconds_to_absolutetime(1250000, &time); constraints.constraint = AbsoluteTime_to_scalar(&time); constraints.preemptible = TRUE; { IOThread thread; thread = workloop->getThread(); thread_policy_set( thread, THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t) & constraints, THREAD_TIME_CONSTRAINT_POLICY_COUNT ); } } return workloop ;}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:28,
示例11: thread_policy_set//TODO : Support Windows and linuxvoid UThread::applyAffinity(){ if(cpuAffinity_>0) {#ifdef WIN32#elif __APPLE__ thread_affinity_policy_data_t affPolicy; affPolicy.affinity_tag = cpuAffinity_; kern_return_t ret = thread_policy_set( mach_thread_self(), THREAD_AFFINITY_POLICY, (integer_t*) &affPolicy, THREAD_AFFINITY_POLICY_COUNT); if(ret != KERN_SUCCESS) { UERROR("thread_policy_set returned %d", ret); }#else /*unsigned long mask = cpuAffinity_; if (pthread_setaffinity_np( pthread_self(), sizeof(mask), &mask) <0) { UERROR("pthread_setaffinity_np failed"); } }*/#endif }}
开发者ID:matlabbe,项目名称:utilite,代码行数:32,
示例12: makeRealtimeint makeRealtime(void){ struct thread_time_constraint_policy ttcpolicy; uint64_t freq = 0; size_t size = sizeof(freq); int ret; ret = sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0); if (ret < 0) { printf("Unable to read CPU frequency, acquisition of real-time scheduling failed./n"); return -1; } printf("sysctl for hw.cpufrequency: %llu/n", freq); /* See http://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/KernelProgramming/scheduler/scheduler.html */ ttcpolicy.period = freq / 160; ttcpolicy.computation = freq / 3300; ttcpolicy.constraint = freq / 2200; ttcpolicy.preemptible = 1; ret = thread_policy_set(mach_thread_self(), THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t) &ttcpolicy, THREAD_TIME_CONSTRAINT_POLICY_COUNT); if (ret) { printf("Unable to set real-time thread priority (%08x)./n", ret); return -1; } printf("Successfully acquired real-time thread priority./n"); return 0;}
开发者ID:Cyclic,项目名称:PulseAudioOSX,代码行数:33,
示例13: iaxci_prioboostbeginint iaxci_prioboostbegin(){ struct thread_time_constraint_policy ttcpolicy; int params [2] = {CTL_HW,HW_BUS_FREQ}; int hzms; size_t sz; int ret; /* get hz */ sz = sizeof (hzms); sysctl (params, 2, &hzms, &sz, NULL, 0); /* make hzms actually hz per ms */ hzms /= 1000; /* give us at least how much? 6-8ms every 10ms (we generally need less) */ ttcpolicy.period = 10 * hzms; /* 10 ms */ ttcpolicy.computation = 2 * hzms; ttcpolicy.constraint = 3 * hzms; ttcpolicy.preemptible = 1; if ( (ret = thread_policy_set(mach_thread_self(), THREAD_TIME_CONSTRAINT_POLICY, (int *)&ttcpolicy, THREAD_TIME_CONSTRAINT_POLICY_COUNT)) != KERN_SUCCESS ) { fprintf(stderr, "thread_policy_set failed: %d./n", ret); } return 0;}
开发者ID:Garalv,项目名称:miumiu,代码行数:29,
示例14: ph_thread_set_affinitybool ph_thread_set_affinity(ph_thread_t *me, int affinity){#ifdef HAVE_PTHREAD_SETAFFINITY_NP# ifdef __linux__ cpu_set_t set;# else /* FreeBSD */ cpuset_t set;#endif CPU_ZERO(&set); CPU_SET(affinity, &set); return pthread_setaffinity_np(me->thr, sizeof(set), &set) == 0;#elif defined(__APPLE__) thread_affinity_policy_data_t data; data.affinity_tag = affinity + 1; return thread_policy_set(pthread_mach_thread_np(me->thr), THREAD_AFFINITY_POLICY, (thread_policy_t)&data, THREAD_AFFINITY_POLICY_COUNT) == 0;#elif defined(HAVE_CPUSET_SETAFFINITY) /* untested bsdish */ cpuset_t set; CPU_ZERO(&set); CPU_SET(affinity, &set); cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(set), set);#elif defined(HAVE_PROCESSOR_BIND) return processor_bind(P_LWPID, me->lwpid, affinity, NULL) == 0;#endif return true;}
开发者ID:atrmat,项目名称:libphenom,代码行数:32,
示例15: setRealtime// https://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/KernelProgramming/scheduler/scheduler.html// Also, from Google Native Client, osx/nacl_thread_nice.c has some related code.// Or, from Google Chrome, platform_thread_mac.mm.void setRealtime() { kern_return_t ret; thread_port_t threadport = pthread_mach_thread_np(pthread_self()); thread_extended_policy_data_t policy; policy.timeshare = 0; ret = thread_policy_set(threadport, THREAD_EXTENDED_POLICY, (thread_policy_t)&policy, THREAD_EXTENDED_POLICY_COUNT); if(ret != KERN_SUCCESS) { fprintf(stderr, "setRealtime() THREAD_EXTENDED_POLICY failed: %d, %s/n", ret, mach_error_string(ret)); return; } thread_precedence_policy_data_t precedence; precedence.importance = 63; ret = thread_policy_set(threadport, THREAD_PRECEDENCE_POLICY, (thread_policy_t)&precedence, THREAD_PRECEDENCE_POLICY_COUNT); if(ret != KERN_SUCCESS) { fprintf(stderr, "setRealtime() THREAD_PRECEDENCE_POLICY failed: %d, %s/n", ret, mach_error_string(ret)); return; } mach_timebase_info_data_t tb_info; mach_timebase_info(&tb_info); double timeFact = ((double)tb_info.denom / (double)tb_info.numer) * 1000000; thread_time_constraint_policy_data_t ttcpolicy; ttcpolicy.period = 2.9 * timeFact; // about 128 frames @44.1KHz ttcpolicy.computation = 0.75 * 2.9 * timeFact; ttcpolicy.constraint = 0.85 * 2.9 * timeFact; ttcpolicy.preemptible = 1; ret = thread_policy_set(threadport, THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t)&ttcpolicy, THREAD_TIME_CONSTRAINT_POLICY_COUNT); if(ret != KERN_SUCCESS) { fprintf(stderr, "setRealtime() THREAD_TIME_CONSTRAINT_POLICY failed: %d, %s/n", ret, mach_error_string(ret)); return; }}
开发者ID:keverets,项目名称:music-player,代码行数:48,
示例16: set_affinitystatic void set_affinity(pthread_t thread, int tag){ thread_affinity_policy theTCPolicy; theTCPolicy.affinity_tag = tag; kern_return_t res = thread_policy_set(pthread_mach_thread_np(thread), THREAD_AFFINITY_POLICY, (thread_policy_t)&theTCPolicy, THREAD_AFFINITY_POLICY_COUNT); if (res == KERN_SUCCESS) { //printf("set_affinity = %d/n", theTCPolicy.affinity_tag); }}
开发者ID:onukore,项目名称:radium,代码行数:9,
示例17: thread_setupintthread_setup(my_policy_type_t pol){ int res; switch (pol) { case MY_POLICY_TIMESHARE: { return 0; } case MY_POLICY_REALTIME: { thread_time_constraint_policy_data_t pol; /* Hard-coded realtime parameters (similar to what Digi uses) */ pol.period = 100000; pol.constraint = CONSTRAINT_NANOS * g_mti.denom / g_mti.numer; pol.computation = COMPUTATION_NANOS * g_mti.denom / g_mti.numer; pol.preemptible = 0; /* Ignored by OS */ res = thread_policy_set(mach_thread_self(), THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t) &pol, THREAD_TIME_CONSTRAINT_POLICY_COUNT); assert(res == 0, fail); break; } case MY_POLICY_FIXEDPRI: { thread_extended_policy_data_t pol; pol.timeshare = 0; res = thread_policy_set(mach_thread_self(), THREAD_EXTENDED_POLICY, (thread_policy_t) &pol, THREAD_EXTENDED_POLICY_COUNT); assert(res == 0, fail); break; } default: { printf("invalid policy type/n"); return 1; } } return 0;fail: return 1;}
开发者ID:JackieXie168,项目名称:xnu,代码行数:44,
示例18: QUARK_Finalize/** This routine will set affinity for the calling thread that has rank 'rank'. Ranks start with 0. If there are multiple instances of QUARK then affinity will be wrong: all ranks 0 will be pinned to core 0. Also, affinity is not resotred when QUARK_Finalize() is called. */int quark_setaffinity(int rank) {#ifndef QUARK_AFFINITY_DISABLE#if (defined QUARK_OS_LINUX) { cpu_set_t set; CPU_ZERO( &set ); CPU_SET( rank, &set );#if (defined HAVE_OLD_SCHED_SETAFFINITY) if( sched_setaffinity( 0, &set ) < 0 )#else /* HAVE_OLD_SCHED_SETAFFINITY */ if( sched_setaffinity( 0, sizeof(set), &set) < 0 )#endif /* HAVE_OLD_SCHED_SETAFFINITY */ { return QUARK_ERR_UNEXPECTED; } return QUARK_SUCCESS; }#elif (defined QUARK_OS_MACOS) { thread_affinity_policy_data_t ap; int ret; ap.affinity_tag = 1; /* non-null affinity tag */ ret = thread_policy_set( mach_thread_self(), THREAD_AFFINITY_POLICY, (integer_t*) &ap, THREAD_AFFINITY_POLICY_COUNT ); if(ret != 0) return QUARK_ERR_UNEXPECTED; return QUARK_SUCCESS; }#elif (defined QUARK_OS_WINDOWS) { DWORD mask = 1 << rank; if( SetThreadAffinityMask(GetCurrentThread(), mask) == 0) return QUARK_ERR_UNEXPECTED; return QUARK_SUCCESS; }#elif (defined QUARK_OS_AIX) { tid_t self_ktid = thread_self (); bindprocessor(BINDTHREAD, self_ktid, rank); return QUARK_SUCCESS; }#else return QUARK_ERR_NOT_SUPPORTED;#endif#endif /* QUARK_AFFINITY_DISABLE */ return QUARK_ERR_NOT_SUPPORTED;}
开发者ID:cjy7117,项目名称:FT-MAGMA,代码行数:65,
示例19: __sender_thread_set_realtimestatic int __sender_thread_set_realtime(uint32_t ptime) { struct thread_time_constraint_policy policy; int params [2] = {CTL_HW, HW_BUS_FREQ}; int ret; // get bus frequence int freq_ns, freq_ms; size_t size = sizeof (freq_ns); if((ret = sysctl (params, 2, &freq_ns, &size, NULL, 0))){ // check errno for more information TSK_DEBUG_ERROR("sysctl() failed with error code=%d", ret); return ret; } freq_ms = freq_ns/1000; /* * THREAD_TIME_CONSTRAINT_POLICY: * * This scheduling mode is for threads which have real time * constraints on their execution. * * Parameters: * * period: This is the nominal amount of time between separate * processing arrivals, specified in absolute time units. A * value of 0 indicates that there is no inherent periodicity in * the computation. * * computation: This is the nominal amount of computation * time needed during a separate processing arrival, specified * in absolute time units. * * constraint: This is the maximum amount of real time that * may elapse from the start of a separate processing arrival * to the end of computation for logically correct functioning, * specified in absolute time units. Must be (>= computation). * Note that latency = (constraint - computation). * * preemptible: This indicates that the computation may be * interrupted, subject to the constraint specified above. */ policy.period = (ptime/2) * freq_ms; // Half of the ptime policy.computation = 2 * freq_ms; policy.constraint = 3 * freq_ms; policy.preemptible = true; if ((ret = thread_policy_set(mach_thread_self(), THREAD_TIME_CONSTRAINT_POLICY, (int *)&policy, THREAD_TIME_CONSTRAINT_POLICY_COUNT)) != KERN_SUCCESS) { TSK_DEBUG_ERROR("thread_policy_set failed(period=%u,computation=%u,constraint=%u) failed with error code= %d", policy.period, policy.computation, policy.constraint, ret); return ret; } return 0;}
开发者ID:yhp920116,项目名称:YunTong,代码行数:56,
示例20: thread_policy_setstatic void *Pt_CallbackProc(void *p){ pt_callback_parameters *parameters = (pt_callback_parameters *) p; int mytime = 1; kern_return_t error; thread_extended_policy_data_t extendedPolicy; thread_precedence_policy_data_t precedencePolicy; extendedPolicy.timeshare = 0; error = thread_policy_set(mach_thread_self(), THREAD_EXTENDED_POLICY, (thread_policy_t)&extendedPolicy, THREAD_EXTENDED_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread timeshare policy", error); } precedencePolicy.importance = THREAD_IMPORTANCE; error = thread_policy_set(mach_thread_self(), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&precedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); if (error != KERN_SUCCESS) { mach_error("Couldn't set thread precedence policy", error); } /* to kill a process, just increment the pt_callback_proc_id */ /* printf("pt_callback_proc_id %d, id %d/n", pt_callback_proc_id, parameters->id); */ while (pt_callback_proc_id == parameters->id) { /* wait for a multiple of resolution ms */ UInt64 wait_time; int delay = mytime++ * parameters->resolution - Pt_Time(); PtTimestamp timestamp; if (delay < 0) delay = 0; wait_time = AudioConvertNanosToHostTime((UInt64)delay * NSEC_PER_MSEC); wait_time += AudioGetCurrentHostTime(); error = mach_wait_until(wait_time); timestamp = Pt_Time(); (*(parameters->callback))(timestamp, parameters->userData); } free(parameters); return NULL;}
开发者ID:Angeldude,项目名称:pure-data,代码行数:43,
示例21: setThreadToPriorityvoid 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); }}
开发者ID:fruitsamples,项目名称:HAL,代码行数:42,
示例22: setThreadAffinity// Schedules the current thread in the affinity set identified by tag n.voidsetThreadAffinity (nat n, nat m GNUC3_ATTRIBUTE(__unused__)){ thread_affinity_policy_data_t policy; policy.affinity_tag = n; thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, (thread_policy_t) &policy, THREAD_AFFINITY_POLICY_COUNT);}
开发者ID:cartazio,项目名称:ghc,代码行数:12,
示例23: ff_mapThreadToCpu/** * /brief Maps the calling thread to the given CPU. * * It maps the calling thread to the given core. It works on Linux OS, Apple * OS, Windows. * * /param cpu_id the ID of the CPU to which the thread will be attached. * /param priority_level TODO * * /return An integet value showing the priority level is returned if * successful. Otherwise /p EINVAL is returned. */static inline int ff_mapThreadToCpu(int cpu_id, int priority_level=0) { if (cpu_id > ff_numCores()) return EINVAL;#if defined(__linux__) && defined(CPU_SET) cpu_set_t mask; CPU_ZERO(&mask); CPU_SET(cpu_id, &mask); if (sched_setaffinity(gettid(), sizeof(mask), &mask) != 0) return EINVAL; return (ff_setPriority(priority_level));#elif defined(__APPLE__) && MAC_OS_X_HAS_AFFINITY // Mac OS does not implement direct pinning of threads onto cores. // Threads can be organised in affinity set. Using requested CPU // tag for the set. Cores under the same L2 cache are not distinguished. // Should be called before running the thread.#define CACHE_LEVELS 3 #define CACHE_L2 2 size_t len; if (sysctlbyname("hw.cacheconfig",NULL, &len, NULL, 0) != 0) { perror("sysctl"); } else { int64_t cacheconfig[len]; if (sysctlbyname("hw.cacheconfig", &cacheconfig[0], &len, NULL, 0) != 0) perror("sysctl: unable to get hw.cacheconfig"); else { /* for (size_t i=0;i<CACHE_LEVELS;i++) std::cerr << " Cache " << i << " shared by " << cacheconfig[i] << " cores/n"; */ struct thread_affinity_policy mypolicy; // Define sets taking in account pinning is performed on L2 mypolicy.affinity_tag = cpu_id/cacheconfig[CACHE_L2]; if ( thread_policy_set(mach_thread_self(), THREAD_AFFINITY_POLICY, (integer_t*) &mypolicy, THREAD_AFFINITY_POLICY_COUNT) != KERN_SUCCESS ) { std::cerr << "Setting affinity of thread ? (" << mach_thread_self() << ") failed!" << std::endl; return EINVAL; } // else { // std::cerr << "Sucessfully set affinity of thread (" << // mach_thread_self() << ") to core " << cpu_id/cacheconfig[CACHE_L2] << "/n"; // } } } return(ff_setPriority(priority_level));#elif (defined(_MSC_VER) || defined(__INTEL_COMPILER)) && defined(_WIN32) if (-1==SetThreadIdealProcessor(GetCurrentThread(),cpu_id)) { perror("ff_mapThreadToCpu:SetThreadIdealProcessor"); return EINVAL; } //std::cerr << "Successfully set affinity of thread " << GetCurrentThreadId() << " to core " << cpu_id << "/n";#else #warning "CPU_SET not defined, cannot map thread to specific CPU"#endif return 0;}
开发者ID:pombredanne,项目名称:mc-fastflow,代码行数:66,
示例24: threadBindToProcessorbool threadBindToProcessor(threadid_t tid, int pnumber){#if defined(_WIN32) HANDLE hThread = OpenThread(THREAD_ALL_ACCESS, 0, tid); if (!hThread) return false; bool success = SetThreadAffinityMask(hThread, 1 << pnumber) != 0; CloseHandle(hThread); return success;#elif (defined(__FreeBSD__) && (__FreeBSD_version >= 702106)) / || defined(__linux) || defined(linux) cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(pnumber, &cpuset); return pthread_setaffinity_np(tid, sizeof(cpuset), &cpuset) == 0;#elif defined(__sun) || defined(sun) return processor_bind(P_LWPID, MAKE_LWPID_PTHREAD(tid), pnumber, NULL) == 0;#elif defined(_AIX) return bindprocessor(BINDTHREAD, (tid_t)tid, pnumber) == 0;#elif defined(__hpux) || defined(hpux) pthread_spu_t answer; return pthread_processor_bind_np(PTHREAD_BIND_ADVISORY_NP, &answer, pnumber, tid) == 0;#elif defined(__APPLE__) struct thread_affinity_policy tapol; thread_port_t threadport = pthread_mach_thread_np(tid); tapol.affinity_tag = pnumber + 1; return thread_policy_set(threadport, THREAD_AFFINITY_POLICY, (thread_policy_t)&tapol, THREAD_AFFINITY_POLICY_COUNT) == KERN_SUCCESS;#else return false;#endif}
开发者ID:4aiman,项目名称:Magichet-stable,代码行数:53,
示例25: SetThreadPrecedenceRString SetThreadPrecedence( float prec ){ // Real values are between 0 and 63. DEBUG_ASSERT( 0.0f <= prec && prec <= 1.0f ); thread_precedence_policy po = { integer_t( lrintf(prec * 63) ) }; kern_return_t ret = thread_policy_set( mach_thread_self(), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&po, THREAD_PRECEDENCE_POLICY_COUNT ); if( ret != KERN_SUCCESS ) return mach_error_string( ret ); return RString();}
开发者ID:Pisces000221,项目名称:stepmania,代码行数:12,
示例26: PyInt_FromLong /* "/Volumes/astraw/src/ve/visionegg-devel.clean/src/darwin_maxpriority.pyx":79 */ __pyx_1 = PyInt_FromLong(__pyx_v_bus_speed); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} __pyx_r = __pyx_1; __pyx_1 = 0; goto __pyx_L0; __pyx_r = Py_None; Py_INCREF(__pyx_r); goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_1); __Pyx_AddTraceback("darwin_maxpriority.get_bus_speed"); __pyx_r = 0; __pyx_L0:; return __pyx_r;}static PyObject *__pyx_f_18darwin_maxpriority_set_self_thread_time_constraint_policy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/static PyObject *__pyx_f_18darwin_maxpriority_set_self_thread_time_constraint_policy(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_period = 0; PyObject *__pyx_v_computation = 0; PyObject *__pyx_v_constraint = 0; PyObject *__pyx_v_preemptible = 0; thread_time_constraint_policy_data_t __pyx_v_ttcpolicy; PyObject *__pyx_r; uint32_t __pyx_1; boolean_t __pyx_2; PyObject *__pyx_3 = 0; static char *__pyx_argnames[] = {"period","computation","constraint","preemptible",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOOO", __pyx_argnames, &__pyx_v_period, &__pyx_v_computation, &__pyx_v_constraint, &__pyx_v_preemptible)) return 0; Py_INCREF(__pyx_v_period); Py_INCREF(__pyx_v_computation); Py_INCREF(__pyx_v_constraint); Py_INCREF(__pyx_v_preemptible); /* "/Volumes/astraw/src/ve/visionegg-devel.clean/src/darwin_maxpriority.pyx":88 */ __pyx_1 = PyInt_AsLong(__pyx_v_period); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; goto __pyx_L1;} __pyx_v_ttcpolicy.period = __pyx_1; /* "/Volumes/astraw/src/ve/visionegg-devel.clean/src/darwin_maxpriority.pyx":89 */ __pyx_1 = PyInt_AsLong(__pyx_v_computation); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; goto __pyx_L1;} __pyx_v_ttcpolicy.computation = __pyx_1; /* "/Volumes/astraw/src/ve/visionegg-devel.clean/src/darwin_maxpriority.pyx":90 */ __pyx_1 = PyInt_AsLong(__pyx_v_constraint); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; goto __pyx_L1;} __pyx_v_ttcpolicy.constraint = __pyx_1; /* "/Volumes/astraw/src/ve/visionegg-devel.clean/src/darwin_maxpriority.pyx":91 */ __pyx_2 = PyInt_AsLong(__pyx_v_preemptible); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} __pyx_v_ttcpolicy.preemptible = __pyx_2; /* "/Volumes/astraw/src/ve/visionegg-devel.clean/src/darwin_maxpriority.pyx":93 */ __pyx_3 = PyInt_FromLong(thread_policy_set(mach_thread_self(),THREAD_TIME_CONSTRAINT_POLICY,((thread_policy_t )(&__pyx_v_ttcpolicy)),THREAD_TIME_CONSTRAINT_POLICY_COUNT)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} __pyx_r = __pyx_3; __pyx_3 = 0; goto __pyx_L0; __pyx_r = Py_None; Py_INCREF(__pyx_r); goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_3); __Pyx_AddTraceback("darwin_maxpriority.set_self_thread_time_constraint_policy"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_period); Py_DECREF(__pyx_v_computation); Py_DECREF(__pyx_v_constraint); Py_DECREF(__pyx_v_preemptible); return __pyx_r;}
开发者ID:Complex501,项目名称:visionegg,代码行数:69,
示例27: pthread_setaffinity_npstatic int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t *cpu_set){ int core; for (core = 0; core < (8 * (int) cpu_size); core++) { if (CPU_ISSET (core, cpu_set)) break; } thread_affinity_policy_data_t policy = { core }; return thread_policy_set (pthread_mach_thread_np (thread), THREAD_AFFINITY_POLICY, (thread_policy_t) &policy, 1);}
开发者ID:anthraxx,项目名称:hashcat,代码行数:13,
示例28: set_realtime// Helper for PsychSetThreadPriority(): Setup of Mach RT scheduling.// We want / "promise to not use more" than "computation" cycles out of every "period" cycles.// Once we started execution, we want to finish our "computation" cycles within at most "constraint" cycles.// We allow / or don't allow to be "isPreemptible" preempted - to finish our "computation" cycles split up into// multiple pieces, but finishing within at most "constraint" cycles.int set_realtime(task_t threadID, int period, int computation, int constraint, psych_bool isPreemptible) { struct thread_time_constraint_policy ttcpolicy; int ret; // Set realtime scheduling with following parameters: ttcpolicy.period = period; ttcpolicy.computation = computation; ttcpolicy.constraint = (constraint >= computation) ? constraint : computation; ttcpolicy.preemptible = (isPreemptible) ? 1 : 0; ret = thread_policy_set(threadID, THREAD_TIME_CONSTRAINT_POLICY, (thread_policy_t) &ttcpolicy, THREAD_TIME_CONSTRAINT_POLICY_COUNT); return(ret);}
开发者ID:eyelink,项目名称:Psychtoolbox-3,代码行数:18,
示例29: definedbool Thread::bindToProcessor(unsigned int proc_number){#if defined(__ANDROID__) return false;#elif defined(_WIN32) return SetThreadAffinityMask(m_thread_handle, 1 << proc_number);#elif __FreeBSD_version >= 702106 || defined(__linux) || defined(linux) cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(proc_number, &cpuset); return pthread_setaffinity_np(m_thread_handle, sizeof(cpuset), &cpuset) == 0;#elif defined(__sun) || defined(sun) return processor_bind(P_LWPID, P_MYID, proc_number, NULL) == 0#elif defined(_AIX) return bindprocessor(BINDTHREAD, m_kernel_thread_id, proc_number) == 0;#elif defined(__hpux) || defined(hpux) pthread_spu_t answer; return pthread_processor_bind_np(PTHREAD_BIND_ADVISORY_NP, &answer, proc_number, m_thread_handle) == 0;#elif defined(__APPLE__) struct thread_affinity_policy tapol; thread_port_t threadport = pthread_mach_thread_np(m_thread_handle); tapol.affinity_tag = proc_number + 1; return thread_policy_set(threadport, THREAD_AFFINITY_POLICY, (thread_policy_t)&tapol, THREAD_AFFINITY_POLICY_COUNT) == KERN_SUCCESS;#else return false;#endif}
开发者ID:00c,项目名称:ayntest_game,代码行数:50,
示例30: pthread_setaffinityint pthread_setaffinity(pthread_t thread, unsigned int core){ /* Convert pthread ID */ mach_port_t mach_thread = pthread_mach_thread_np(thread); /* core + 1 to avoid using THREAD_AFFINITY_TAG_NULL */ thread_affinity_policy_data_t policy = { core + 1 }; kern_return_t rc = thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, (thread_policy_t) &policy, THREAD_AFFINITY_POLICY_COUNT); return (rc == KERN_SUCCESS ? 0 : -1);}
开发者ID:EnjoyHacking,项目名称:flowgrind,代码行数:14,
注:本文中的thread_policy_set函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ thread_register_notifier函数代码示例 C++ thread_mtx_lock函数代码示例 |