本文整理汇总了C++中sched_get_priority_min函数的典型用法代码示例。如果您正苦于以下问题:C++ sched_get_priority_min函数的具体用法?C++ sched_get_priority_min怎么用?C++ sched_get_priority_min使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sched_get_priority_min函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: controler
/* thread function 1 */
void * controler ( void * arg )
{
int ret = 0;
/* Wait until the policy has been changed. */
ret = pthread_barrier_wait( arg );
if ( ( ret != 0 ) && ( ret != PTHREAD_BARRIER_SERIAL_THREAD ) )
{
UNRESOLVED( ret, "barrier wait failed" );
}
/* check the thread attributes have been applied
(we only check what is reported, not the real behavior)
*/
check_param( pthread_self(), SCHED_RR, sched_get_priority_min( SCHED_RR ) );
return NULL;
}
示例2: main
int main(int argc, char **argv)
{
int result = -1;
result = sched_get_priority_min(SCHED_SPORADIC);
if(result != -1 && errno == 0 ) {
printf("The minimum priority for policy SCHED_SPORADIC is %i.\n",
result);
printf("Test PASSED\n");
return PTS_PASS;
} else {
perror("An error occurs");
return PTS_FAIL;
}
printf("This code should not be executed.\n");
return PTS_UNRESOLVED;
}
示例3: sched_getscheduler
void Thread::setPriority(Priority _priority) {
#if ARX_HAVE_SCHED_GETSCHEDULER
int policy = sched_getscheduler(0);
#else
int policy = SCHED_RR;
#endif
int min = sched_get_priority_min(policy);
int max = sched_get_priority_max(policy);
priority = min + ((_priority - Lowest) * (max - min) / (Highest - Lowest));
if(started && min != max) {
sched_param param;
param.sched_priority = priority;
pthread_setschedparam(thread, policy, ¶m);
}
}
示例4: ltos_sparam
static int
ltos_sparam(int policy, struct lx_sched_param *lsp, struct sched_param *sp)
{
struct lx_sched_param ls;
int smin = sched_get_priority_min(policy);
int smax = sched_get_priority_max(policy);
if (uucopy(lsp, &ls, sizeof (struct lx_sched_param)) != 0)
return (-errno);
bzero(sp, sizeof (struct sched_param));
/*
* Linux has a fixed priority range, 0 - 99, which we need to convert to
* Solaris's dynamic range. Linux considers lower numbers to be
* higher priority, so we'll invert the priority within Solaris's range.
*
* The formula to convert between ranges is:
*
* L * (smax - smin)
* S = ----------------- + smin
* (lmax - lmin)
*
* where S is the Solaris equivalent of the linux priority L.
*
* To invert the priority, we use:
* S' = smax - S + smin
*
* Together, these two formulas become:
*
* L * (smax - smin)
* S = smax - ----------------- + 2smin
* 99
*/
sp->sched_priority = smax -
((ls.lx_sched_prio * (smax - smin)) / LX_PRI_MAX) + 2*smin;
lx_debug("ltos_sparam: linux prio %d = Solaris prio %d "
"(Solaris range %d,%d)\n", ls.lx_sched_prio, sp->sched_priority,
smin, smax);
return (0);
}
示例5: main
int main(int argc, char *argv[])
{
int pri_boost, numcpus;
setup();
pass_criteria = CHECK_LIMIT;
rt_init("hin:", parse_args, argc, argv);
numcpus = sysconf(_SC_NPROCESSORS_ONLN);
/* Max no. of busy threads should always be less than/equal the no. of cpus
Otherwise, the box will hang */
if (rt_threads == -1 || rt_threads > numcpus) {
rt_threads = numcpus;
printf("Maximum busy thread count(%d), "
"should not exceed number of cpus(%d)\n", rt_threads,
numcpus);
printf("Using %d\n", numcpus);
}
/* Test boilder plate: title and parameters */
printf("\n-------------------\n");
printf("Priority Preemption\n");
printf("-------------------\n\n");
printf("Busy Threads: %d\n", rt_threads);
printf("Interrupter Threads: %s\n",
int_threads ? "Enabled" : "Disabled");
printf("Worker Threads: %d\n\n", NUM_WORKERS);
pri_boost = 81;
create_fifo_thread(master_thread, (void *)0,
sched_get_priority_min(SCHED_FIFO) + pri_boost);
/* wait for threads to complete */
join_threads();
printf
("\nCriteria: All threads appropriately preempted within %d loop(s)\n",
(int)pass_criteria);
printf("Result: %s\n", ret ? "FAIL" : "PASS");
return ret;
}
示例6: sched_get_priority_min
//==============================================================================
JUCE_API void JUCE_CALLTYPE Process::setPriority (const ProcessPriority prior)
{
const int policy = (prior <= NormalPriority) ? SCHED_OTHER : SCHED_RR;
const int minp = sched_get_priority_min (policy);
const int maxp = sched_get_priority_max (policy);
struct sched_param param;
switch (prior)
{
case LowPriority:
case NormalPriority: param.sched_priority = 0; break;
case HighPriority: param.sched_priority = minp + (maxp - minp) / 4; break;
case RealtimePriority: param.sched_priority = minp + (3 * (maxp - minp) / 4); break;
default: jassertfalse; break;
}
pthread_setschedparam (pthread_self(), policy, ¶m);
}
示例7: main
int main(int argc, const char *argv[])
{
int res;
pthread_t a_thread;
pthread_attr_t thread_attr;
int max_priority;
int min_priority;
struct sched_param scheduling_value;
res = pthread_attr_init(&thread_attr);
if (res != 0) {
perror("Attribute creation failed");
exit(EXIT_FAILURE);
}
res = pthread_attr_setschedpolicy(&thread_attr, SCHED_OTHER);
if (res != 0) {
perror("Setting schedpolicy failed");
exit(EXIT_FAILURE);
}
res = pthread_create(&a_thread, &thread_attr,
thread_function, (void *)message);
if (res != 0) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
max_priority = sched_get_priority_max(SCHED_OTHER);
min_priority = sched_get_priority_min(SCHED_OTHER);
scheduling_value.sched_priority = min_priority;
res = pthread_attr_setschedparam(&thread_attr, &scheduling_value);
if (res != 0) {
perror("Setting schedpolicy failed");
exit(EXIT_FAILURE);
}
(void)pthread_attr_destroy(&thread_attr);
while (!thread_finished) {
printf("Waiting for thread to say it's finished...\n");
sleep(1);
}
printf("Other thread finished, bye!\n");
exit(EXIT_SUCCESS);
}
示例8: main
int
main()
{
pthread_t t;
void * result = NULL;
int result2;
struct sched_param param;
assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1);
assert((minPrio = sched_get_priority_min(SCHED_OTHER)) != -1);
assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0);
assert(pthread_join(t, &result) == 0);
assert(pthread_barrier_init(&startBarrier, NULL, 2) == 0);
assert(pthread_barrier_init(&endBarrier, NULL, 2) == 0);
/* Set the thread's priority to a known initial value.
* If the new priority is invalid then the threads priority
* is unchanged from the previous value.
*/
SetThreadPriority(pthread_getw32threadhandle_np(pthread_self()),
PTW32TEST_THREAD_INIT_PRIO);
for (param.sched_priority = minPrio;
param.sched_priority <= maxPrio;
param.sched_priority++)
{
assert(pthread_create(&t, NULL, func, NULL) == 0);
assert(pthread_setschedparam(t, SCHED_OTHER, ¶m) == 0);
result2 = pthread_barrier_wait(&startBarrier);
assert(result2 == 0 || result2 == PTHREAD_BARRIER_SERIAL_THREAD);
result2 = pthread_barrier_wait(&endBarrier);
assert(result2 == 0 || result2 == PTHREAD_BARRIER_SERIAL_THREAD);
assert(GetThreadPriority(pthread_getw32threadhandle_np(t)) ==
validPriorities[param.sched_priority+(PTW32TEST_MAXPRIORITIES/2)]);
pthread_join(t, &result);
assert(param.sched_priority == (int)result);
}
return 0;
}
示例9: test_priority
void test_priority(const char *const name, const int policy)
{
const pid_t me = getpid();
struct sched_param param;
param.sched_priority = sched_get_priority_max(policy);
printf("sched_get_priority_max(%s) = %d\n", name, param.sched_priority);
if (sched_setscheduler(me, policy, ¶m) == -1)
printf("sched_setscheduler(getpid(), %s, { %d }): %s.\n", name, param.sched_priority, strerror(errno));
else
printf("sched_setscheduler(getpid(), %s, { %d }): Ok.\n", name, param.sched_priority);
param.sched_priority = sched_get_priority_min(policy);
printf("sched_get_priority_min(%s) = %d\n", name, param.sched_priority);
if (sched_setscheduler(me, policy, ¶m) == -1)
printf("sched_setscheduler(getpid(), %s, { %d }): %s.\n", name, param.sched_priority, strerror(errno));
else
printf("sched_setscheduler(getpid(), %s, { %d }): Ok.\n", name, param.sched_priority);
}
示例10: sched_get_priority_min
/* thread function 2 */
void *changer(void *arg)
{
int ret = 0;
struct sched_param sp;
sp.sched_priority = sched_get_priority_min(SCHED_RR);
if (sp.sched_priority < 0) {
UNTESTED("Failed to get min SCHED_RR range");
}
/* set the other thread's policy */
ret = pthread_setschedparam(*(pthread_t *) arg, SCHED_RR, &sp);
if (ret != 0) {
UNRESOLVED(ret, "Failed to set other's thread policy");
}
return NULL;
}
示例11: PJ_DEF
/*
* Get the lowest priority value available on this system.
*/
PJ_DEF(int) pj_thread_get_prio_min(pj_thread_t *thread)
{
struct sched_param param;
int policy;
int rc;
rc = pthread_getschedparam(thread->thread, &policy, ¶m);
if (rc != 0)
return -1;
#if defined(_POSIX_PRIORITY_SCHEDULING)
return sched_get_priority_min(policy);
#elif defined __OpenBSD__
/* Thread prio min/max are declared in OpenBSD private hdr */
return 0;
#else
pj_assert("pj_thread_get_prio_min() not supported!");
return 0;
#endif
}
示例12: task
static void task(rtems_task_argument arg)
{
rtems_status_code sc;
(void) arg;
rtems_test_assert(rtems_get_current_processor() == 1);
rtems_test_assert(sched_get_priority_min(SCHED_RR) == 1);
rtems_test_assert(sched_get_priority_max(SCHED_RR) == 126);
sc = rtems_semaphore_obtain(sema_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
rtems_test_assert(sc == RTEMS_NOT_DEFINED);
sc = rtems_event_transient_send(main_task_id);
rtems_test_assert(sc == RTEMS_SUCCESSFUL);
while (1) {
/* Do nothing */
}
}
示例13: check_priority_range
void uhd::set_thread_priority(float priority, bool realtime){
check_priority_range(priority);
//when realtime is not enabled, use sched other
int policy = (realtime)? SCHED_RR : SCHED_OTHER;
//we cannot have below normal priority, set to zero
if (priority < 0) priority = 0;
//get the priority bounds for the selected policy
int min_pri = sched_get_priority_min(policy);
int max_pri = sched_get_priority_max(policy);
if (min_pri == -1 or max_pri == -1) throw uhd::os_error("error in sched_get_priority_min/max");
//set the new priority and policy
sched_param sp;
sp.sched_priority = int(priority*(max_pri - min_pri)) + min_pri;
int ret = pthread_setschedparam(pthread_self(), policy, &sp);
if (ret != 0) throw uhd::os_error("error in pthread_setschedparam");
}
示例14: pthread_attr_init
void *child_thread(void *arg)
{
int policy;
int max_priority,min_priority;
struct sched_param param;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setinheritsched(&attr,PTHREAD_EXPLICIT_SCHED);
pthread_attr_getinheritsched(&attr,&policy);
if(policy == PTHREAD_EXPLICIT_SCHED)
{
printf("inheritsched:PTHREAD_EXPLICIT_SCHED\n");
}
if(policy == PTHREAD_INHERIT_SCHED)
{
printf("Inheritsched:PTHREAD_INHERIT_SCHED\n");
}
pthread_attr_setschedpolicy(&attr,SCHED_RR);
pthread_attr_getschedpolicy(&attr,&policy);
if(policy ==SCHED_FIFO)
{
printf("schedpolicy: SCHED_FIFO\n");
}
if(policy == SCHED_RR)
printf("schedpolicy: SCHED_RR\n");
if(policy == SCHED_OTHER)
printf("schedpolicy: SCHED_OTHER\n");
sched_get_priority_max(max_priority);
sched_get_priority_min(min_priority);
printf("max priority: %u\n",max_priority);
printf("min priority: %u\n",min_priority);
param.sched_priority = max_priority;
pthread_attr_setschedparam(&attr,¶m);
printf("sched_priority:%u\n",param.sched_priority);
pthread_attr_destroy(&attr);
}
示例15: rtaudio_boost_priority
static PyObject *
rtaudio_boost_priority(PyObject *obj, PyObject *args)
{
#if defined(__LINUX_ALSA__) || defined(__LINUX_OSS__) || defined(__LINUX_JACK__)
struct sched_param schp = { 0 };
int priority = (sched_get_priority_max(SCHEDULER_POLICY) -
sched_get_priority_min(SCHEDULER_POLICY)) / 2;
schp.sched_priority = priority;
if (sched_setscheduler(0, SCHEDULER_POLICY, &schp) != 0)
{
PyErr_Format(RtAudioError, "insufficient priveledges");
return NULL;
}
/* We are running at high priority so we should have a watchdog in
case audio goes wild. */
#endif
#if defined(__MACOSX_CORE__)
struct sched_param sp;
memset(&sp, 0, sizeof(struct sched_param));
int policy;
if (pthread_getschedparam(pthread_self(), &policy, &sp) == -1)
{
PyErr_SetString(RtAudioError, strerror(errno));
return NULL;
}
sp.sched_priority += 40;
if (pthread_setschedparam(pthread_self(), SCHED_RR, &sp) == -1)
{
PyErr_SetString(RtAudioError, strerror(errno));
return NULL;
}
#endif
Py_RETURN_NONE;
}