本文整理汇总了C++中pthread_setschedparam函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_setschedparam函数的具体用法?C++ pthread_setschedparam怎么用?C++ pthread_setschedparam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_setschedparam函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: setThreadPriority
//-------------------------------------------------------------------------
void setThreadPriority(
Thread::native_handle_type handle,
ThreadPriorities threadPriority
)
{
#ifndef _WIN32
const int policy = SCHED_RR;
const int minPrio = sched_get_priority_min(policy);
const int maxPrio = sched_get_priority_max(policy);
sched_param param;
switch (threadPriority)
{
case ThreadPriority_LowPriority:
param.sched_priority = minPrio + 1;
break;
case ThreadPriority_NormalPriority:
param.sched_priority = (minPrio + maxPrio) / 2;
break;
case ThreadPriority_HighPriority:
param.sched_priority = maxPrio - 3;
break;
case ThreadPriority_HighestPriority:
param.sched_priority = maxPrio - 2;
break;
case ThreadPriority_RealtimePriority:
param.sched_priority = maxPrio - 1;
break;
}
pthread_setschedparam(handle, policy, ¶m);
#else
int priority = THREAD_PRIORITY_NORMAL;
switch (threadPriority) {
case ThreadPriority_LowPriority: priority = THREAD_PRIORITY_LOWEST; break;
case ThreadPriority_NormalPriority: priority = THREAD_PRIORITY_NORMAL; break;
case ThreadPriority_HighPriority: priority = THREAD_PRIORITY_ABOVE_NORMAL; break;
case ThreadPriority_HighestPriority: priority = THREAD_PRIORITY_HIGHEST; break;
case ThreadPriority_RealtimePriority: priority = THREAD_PRIORITY_TIME_CRITICAL; break;
}
#ifndef WINRT
auto result = SetThreadPriority(handle, priority);
assert(0 != result);
#endif //ndef WINRT
#endif //_WIN32
}
开发者ID:robin-raymond,项目名称:zsLib,代码行数:46,代码来源:zsLib_MessageQueueThread.cpp
示例2: perror
void AExecutable::SetThreadAffinity(boost::thread* daThread, unsigned short threadPriority, std::vector<short> CPUsToBind, int scheduler) {
#ifndef __APPLE__
int policy;
pthread_t threadID = (pthread_t) (daThread->native_handle());
if (scheduler > 0) {
sched_param param;
if (pthread_getschedparam(threadID, &policy, ¶m) != 0) {
perror("pthread_getschedparam");
exit(EXIT_FAILURE);
}
/**
* Set scheduling algorithm
* Possible values: SCHED_FIFO, SCHED_RR, SCHED_OTHER
*/
policy = scheduler;
param.sched_priority = threadPriority;
if (pthread_setschedparam(threadID, policy, ¶m) != 0) {
perror("pthread_setschedparam");
exit(EXIT_FAILURE);
}
}
if (CPUsToBind.size() > 0) {
/**
* Bind the thread to CPUs from CPUsToBind
*/
cpu_set_t mask;
CPU_ZERO(&mask);
for (unsigned int i = 0; i < CPUsToBind.size(); i++) {
if (CPUsToBind[i] == -1) {
CPU_ZERO(&mask);
break;
}
CPU_SET(CPUsToBind[i], &mask);
}
if (pthread_setaffinity_np(threadID, sizeof(mask), &mask) < 0) {
throw NA62Error("Unable to bind threads to specific CPUs!");
}
}
#endif
}
开发者ID:glehmannmiotto,项目名称:na62-farm-lib,代码行数:45,代码来源:AExecutable.cpp
示例3: myosd_init
void myosd_init(void)
{
int res = 0;
struct sched_param param;
if (!lib_inited )
{
printf("myosd_init\n");
//myosd_set_video_mode(320,240,320,240);
printf("myosd_dbl_buffer %d\n",myosd_dbl_buffer);
if(myosd_dbl_buffer)
myosd_screen15 = myosd_screen;
else
myosd_screen15 = img_buffer;
if(videot_running==0)
{
res = pthread_create(&main_tid, NULL, threaded_video, NULL);
if(res!=0)printf("Error setting creating pthread %d \n",res);
//param.sched_priority = 67;
//param.sched_priority = 50;
//param.sched_priority = 46;
//param.sched_priority = 100;
printf("video priority %d\n",video_thread_priority);
param.sched_priority = video_thread_priority;
int policy;
if(video_thread_priority_type == 1)
policy = SCHED_OTHER;
else if(video_thread_priority_type == 2)
policy = SCHED_RR;
else
policy = SCHED_FIFO;
if(pthread_setschedparam(main_tid, policy, ¶m) != 0)
printf("Error setting pthread priority\n");
videot_running = 1;
}
lib_inited = 1;
}
}
开发者ID:i-willh,项目名称:imame4all,代码行数:45,代码来源:osd-ios.c
示例4: g_thread_set_priority_posix_impl
static void
g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority)
{
#ifdef HAVE_PRIORITIES
# ifdef G_THREADS_IMPL_POSIX
struct sched_param sched;
int policy;
posix_check_for_error (pthread_getschedparam (*(pthread_t*)thread,
&policy, &sched));
sched.sched_priority = g_thread_map_priority (priority);
posix_check_for_error (pthread_setschedparam (*(pthread_t*)thread,
policy, &sched));
# else /* G_THREADS_IMPL_DCE */
posix_check_for_error (pthread_setprio (*(pthread_t*)thread,
g_thread_map_priority (priority)));
# endif
#endif /* HAVE_PRIORITIES */
}
开发者ID:Onjrew,项目名称:OpenEV,代码行数:18,代码来源:gthread-posix.c
示例5: sal_splhi
int
sal_splhi(void)
{
#ifdef SAL_SPL_NO_PREEMPT
struct sched_param param;
int policy;
if (pthread_getschedparam(pthread_self(), &policy, ¶m) == 0) {
/* Interrupt thread uses SCHED_RR and should be left alone */
if (policy != SCHED_RR) {
param.sched_priority = 90;
pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m);
}
}
#endif
sal_mutex_take(spl_mutex, sal_mutex_FOREVER);
return ++spl_level;
}
开发者ID:ariavie,项目名称:bcm,代码行数:18,代码来源:spl.c
示例6: pthread_create
void Core_ThreadImpl::startImpl(Runnable& target)
{
if (m_pData->pTarget)
{
return;
}
m_pData->pTarget = ⌖
m_pData->isRun=true;
pthread_create(&m_pData->thread, NULL, entry, this);
if (m_pData->prio != PRIO_NORMAL_IMPL)
{
struct sched_param par;
par.sched_priority = mapPrio(m_pData->prio);
pthread_setschedparam(m_pData->thread, SCHED_OTHER, &par);
}
}
开发者ID:byteman,项目名称:rtspcamera,代码行数:18,代码来源:Core_Thread_POSIX.cpp
示例7: pthread_self
/** Called during startup to increase thread priority. */
void Thread::high_priority() {
struct sched_param param;
int policy;
pthread_t id = pthread_self();
// save original scheduling parameters
pthread_getschedparam(id, &normal_sched_policy_, &normal_thread_param_);
// set to high priority
param = normal_thread_param_;
param.sched_priority = SCHED_HIGH_PRIORITY; // magick number
policy = SCHED_RR; // realtime, round robin
if (pthread_setschedparam(id, policy, ¶m)) {
fprintf(stderr, "Could not set thread priority to %i (%s). You might need to run the application as super user.\n", param.sched_priority, strerror(errno));
}
}
开发者ID:gaspard,项目名称:oscit,代码行数:19,代码来源:thread.cpp
示例8: perror
void datalink_module::start(void)
{
// create thread
thread_running = true;
the_thread = boost::thread( boost::bind(&datalink_module::loop, this));
struct sched_param thread_param;
thread_param.sched_priority = 5;
pthread_t threadID = (pthread_t) the_thread.native_handle();
int retcode;
if ((retcode = pthread_setschedparam(threadID, SCHED_FIFO, &thread_param)) != 0)
{
errno = retcode;
perror("pthread_setschedparam");
}
}
开发者ID:Tri-o-copter,项目名称:Brainware,代码行数:18,代码来源:datalink_module.cpp
示例9: BoostThreadPriority
bool
BoostThreadPriority(SDL_Thread* inThread) {
#if defined(_POSIX_PRIORITY_SCHEDULING)
pthread_t theTargetThread = (pthread_t) SDL_GetThreadID(inThread);
int theSchedulingPolicy;
struct sched_param theSchedulingParameters;
if(pthread_getschedparam(theTargetThread, &theSchedulingPolicy, &theSchedulingParameters) != 0)
return false;
theSchedulingParameters.sched_priority =
sched_get_priority_max(theSchedulingPolicy);
if(pthread_setschedparam(theTargetThread, theSchedulingPolicy, &theSchedulingParameters) != 0)
return false;
#endif
return true;
}
开发者ID:Aleph-One-Marathon,项目名称:alephone,代码行数:18,代码来源:thread_priority_sdl_posix.cpp
示例10: mapPrio
void ThreadImpl::setPriorityImpl(int prio)
{
if (prio != _pData->prio)
{
_pData->prio = prio;
_pData->policy = SCHED_OTHER;
if (isRunningImpl())
{
struct sched_param par; struct MyStruct
{
};
par.sched_priority = mapPrio(_pData->prio, SCHED_OTHER);
if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
throw SystemException("cannot set thread priority");
}
}
}
开发者ID:jacklicn,项目名称:macchina.io,代码行数:18,代码来源:Thread_POSIX.cpp
示例11: set_realtime_prio
static void set_realtime_prio ()
{
#ifdef HAVE_SCHED_GET_PRIORITY_MAX
int rc;
if (options_get_int("UseRealtimePriority")) {
struct sched_param param;
param.sched_priority = sched_get_priority_max(SCHED_RR);
rc = pthread_setschedparam (pthread_self (), SCHED_RR, ¶m);
if (rc != 0)
logit ("Can't set realtime priority: %s", strerror (rc));
}
#else
logit ("No sched_get_priority_max() function: realtime priority not "
"used.");
#endif
}
开发者ID:Manishearth,项目名称:moc,代码行数:18,代码来源:out_buf.c
示例12: SC_LinuxSetRealtimePriority
static void SC_LinuxSetRealtimePriority(pthread_t thread, int priority)
{
int policy;
struct sched_param param;
pthread_getschedparam(thread, &policy, ¶m);
policy = SCHED_FIFO;
const int minprio = sched_get_priority_min(policy);
const int maxprio = sched_get_priority_max(policy);
param.sched_priority = sc_clip(priority, minprio, maxprio);
int err = pthread_setschedparam(thread, policy, ¶m);
if (err != 0) {
post("Couldn't set realtime scheduling priority %d: %s\n",
param.sched_priority, strerror(err));
}
}
开发者ID:ELVIS-Project,项目名称:VISIntervalSonifier,代码行数:18,代码来源:PyrSched.cpp
示例13: if
bool Thread::setPriority(int prior)
{
#ifdef _WIN32
if ( !handle )
return 0;
if ( prior > 3 )
prior = 3;
else if ( prior < - 4 )
prior = -4;
int tp;
switch( prior )
{
case +3:
tp = THREAD_PRIORITY_TIME_CRITICAL;
break;
case +2:
tp = THREAD_PRIORITY_HIGHEST;
break;
case +1:
tp = THREAD_PRIORITY_ABOVE_NORMAL;
break;
case 0:
tp = THREAD_PRIORITY_NORMAL;
break;
case -1:
tp = THREAD_PRIORITY_BELOW_NORMAL;
break;
case -2:
tp = THREAD_PRIORITY_LOWEST;
break;
case -3:
tp = THREAD_PRIORITY_IDLE;
break;
default:
tp = THREAD_PRIORITY_NORMAL;
}
return SetThreadPriority( (HANDLE)handle, tp ) != FALSE;
#else
struct sched_param param;
param.sched_priority = -prior;
/*int ret =*/ pthread_setschedparam (*(pthread_t *)handle, SCHED_OTHER, ¶m);
return 1;
#endif
}
开发者ID:kmar,项目名称:cheng4,代码行数:44,代码来源:thread.cpp
示例14: SetPriority
/*!
* \brief Sets the priority of the currently running thread.
*
* \internal
*
* \return
* \li \c 0 on success.
* \li \c EINVAL invalid priority or the result of GerLastError.
*/
static int SetPriority(
/*! . */
ThreadPriority priority)
{
#if defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
int retVal = 0;
int currentPolicy;
int minPriority = 0;
int maxPriority = 0;
int actPriority = 0;
int midPriority = 0;
struct sched_param newPriority;
int sched_result;
pthread_getschedparam(ithread_self(), ¤tPolicy, &newPriority);
minPriority = sched_get_priority_min(currentPolicy);
maxPriority = sched_get_priority_max(currentPolicy);
midPriority = (maxPriority - minPriority) / 2;
switch (priority) {
case LOW_PRIORITY:
actPriority = minPriority;
break;
case MED_PRIORITY:
actPriority = midPriority;
break;
case HIGH_PRIORITY:
actPriority = maxPriority;
break;
default:
retVal = EINVAL;
goto exit_function;
};
newPriority.sched_priority = actPriority;
sched_result = pthread_setschedparam(ithread_self(), currentPolicy, &newPriority);
retVal = (sched_result == 0 || errno == EPERM) ? 0 : sched_result;
exit_function:
return retVal;
#else
return 0;
priority = priority;
#endif
}
开发者ID:philippe44,项目名称:pupnp,代码行数:53,代码来源:ThreadPool.c
示例15: mas_ticker_start
/* naming : pthread_create = start */
int
mas_ticker_start( const mas_options_t * popts )
{
CTRL_PREPARE;
/* EVAL_PREPARE; */
int r = 0;
MFP( "\x1b]2;starting ticker; mode:%d\x7", ctrl.ticker_mode );
if ( !ctrl.threads.n.ticker.thread )
{
{
( void ) /* r = */ pthread_attr_getstack( &ctrl.thglob.ticker_attr, &ticker_stackaddr, &ticker_stacksize );
tMSG( "creating ticker thread stack:%lu @ %p", ( unsigned long ) ticker_stacksize, ticker_stackaddr );
HMSG( "+ TICKER mode %d", ctrl.ticker_mode );
}
/* if ( !tmp ) */
/* tmp = mas_malloc( 4321 ); */
MAS_LOG( "starting ticker th." );
/* r = mas_xpthread_create( &ctrl.threads.n.ticker.thread, mas_ticker_th, MAS_THREAD_TICKER, NULL ); */
r = pthread_create( &ctrl.threads.n.ticker.thread, &ctrl.thglob.ticker_attr, mas_ticker_th, NULL );
#ifdef SCHED_IDLE
{
int policy, rs;
struct sched_param sched;
rs = pthread_getschedparam( ctrl.threads.n.ticker.thread, &policy, &sched );
/* SCHED_IDLE ... SCHED_RR */
rs = pthread_setschedparam( ctrl.threads.n.ticker.thread, SCHED_IDLE, &sched );
/* rs = pthread_getschedparam( ctrl.threads.n.ticker.thread, &policy, &sched ); */
MAS_LOG( "(%d) created(?) ticker thread [%lx] %d - %d (%d)", r, ctrl.threads.n.ticker.thread, policy, sched.sched_priority, rs );
tMSG( "(%d) created(?) ticker thread [%lx] %d - %d (%d)", r, ctrl.threads.n.ticker.thread, policy, sched.sched_priority, rs );
}
#else
MAS_LOG( "(%d) created(?) ticker thread [%lx]", r, ctrl.threads.n.ticker.thread );
#endif
}
else
{
MAS_LOG( "running w/o ticker th." );
}
return r;
}
开发者ID:mastarink,项目名称:github-zocromas,代码行数:45,代码来源:mas_ticker.c
示例16: set_thread_priority
void
set_thread_priority(pthread_t thread, const gchar * name, gboolean realtime,
gint priority) {
struct sched_param param;
int policy, priority_min, priority_max;
int err;
if ((err = pthread_getschedparam(thread, &policy, ¶m)) != 0) {
g_debug("cannot get scheduling policy for %s thread: %s",
name, g_strerror(err));
return;
}
if (realtime) {
policy = SCHED_FIFO;
}
priority_min = sched_get_priority_min(policy);
priority_max = sched_get_priority_max(policy);
if (priority != -1) {
if (priority < priority_min) {
g_warning("%s thread priority (%d) too low, set to %d",
name, priority, priority_min);
priority = priority_min;
} else if (priority > priority_max) {
g_warning("%s thread priority (%d) too high, set to %d",
name, priority, priority_max);
priority = priority_max;
}
param.sched_priority = priority;
} else {
if (param.sched_priority < priority_min) {
param.sched_priority = priority_min;
} else if (param.sched_priority > priority_max) {
param.sched_priority = priority_max;
}
}
if ((err = pthread_setschedparam(thread, policy, ¶m)) != 0) {
g_warning("cannot set scheduling policy for %s thread: %s",
name, g_strerror(err));
}
}
开发者ID:alex1818,项目名称:aqualung,代码行数:44,代码来源:athread.c
示例17: if
void Threads::setThreadPriority(BaseLib::Obj* baseLib, pthread_t thread, int32_t priority, int32_t policy)
{
try
{
if(!baseLib->settings.prioritizeThreads()) return;
if(priority == -1)
{
baseLib->out.printWarning("Warning: Priority of -1 was passed to setThreadPriority.");
priority = 0;
policy = SCHED_OTHER;
}
if(policy == SCHED_OTHER) return;
if((policy == SCHED_FIFO || policy == SCHED_RR) && (priority < 1 || priority > 99)) throw Exception("Invalid thread priority for SCHED_FIFO or SCHED_RR: " + std::to_string(priority));
else if((policy == SCHED_IDLE || policy == SCHED_BATCH) && priority != 0) throw Exception("Invalid thread priority for SCHED_IDLE: " + std::to_string(priority));
sched_param schedParam;
schedParam.sched_priority = priority;
int32_t error;
//Only use SCHED_FIFO or SCHED_RR
if((error = pthread_setschedparam(thread, policy, &schedParam)) != 0)
{
if(error == EPERM)
{
baseLib->out.printError("Could not set thread priority. The executing user does not have enough privileges. Please run \"ulimit -r 100\" before executing Homegear.");
}
else if(error == ESRCH) baseLib->out.printError("Could not set thread priority. Thread could not be found.");
else if(error == EINVAL) baseLib->out.printError("Could not set thread priority: policy is not a recognized policy, or param does not make sense for the policy.");
else baseLib->out.printError("Error: Could not set thread priority to " + std::to_string(priority) + " Error: " + std::to_string(error));
baseLib->settings.setPrioritizeThreads(false);
}
else baseLib->out.printDebug("Debug: Thread priority successfully set to: " + std::to_string(priority), 7);
}
catch(const std::exception& ex)
{
baseLib->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(const Exception& ex)
{
baseLib->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
}
catch(...)
{
baseLib->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
}
}
开发者ID:skohlmus,项目名称:Homegear,代码行数:44,代码来源:Threads.cpp
示例18: hrestimer_addInstance
//------------------------------------------------------------------------------
tOplkError hrestimer_addInstance(void)
{
tOplkError ret = kErrorOk;
UINT index;
struct sched_param schedParam;
tHresTimerInfo* pTimerInfo;
OPLK_MEMSET(&hresTimerInstance_l, 0, sizeof(hresTimerInstance_l));
/* Initialize timer threads for all usable timers. */
for (index = 0; index < TIMER_COUNT; index++)
{
pTimerInfo = &hresTimerInstance_l.aTimerInfo[index];
pTimerInfo->fTerminate = FALSE;
#ifdef HIGH_RESK_TIMER_LATENCY_DEBUG
pTimerInfo->maxLatency = 0;
pTimerInfo->minLatency = 999999999;
#endif
if (sem_init(&pTimerInfo->syncSem, 0, 0) != 0)
{
DEBUG_LVL_ERROR_TRACE("%s() Couldn't init semaphore!\n", __func__);
return kErrorNoResource;
}
if (pthread_create(&pTimerInfo->timerThreadId, NULL, timerThread, pTimerInfo) != 0)
{
sem_destroy(&pTimerInfo->syncSem);
return kErrorNoResource;
}
schedParam.__sched_priority = CONFIG_THREAD_PRIORITY_HIGH;
if (pthread_setschedparam(pTimerInfo->timerThreadId, SCHED_FIFO, &schedParam) != 0)
{
DEBUG_LVL_ERROR_TRACE("%s() Couldn't set thread scheduling parameters!\n", __func__);
sem_destroy(&pTimerInfo->syncSem);
pthread_cancel(pTimerInfo->timerThreadId);
return kErrorNoResource;
}
}
return ret;
}
开发者ID:Kalycito-open-automation,项目名称:openPOWERLINK_V2_old_25-06-2014,代码行数:45,代码来源:hrestimer-posix_clocknanosleep.c
示例19: vm_thread_set_scheduling
int32_t vm_thread_set_scheduling(vm_thread* thread, void* params)
{
int32_t i_res = 1;
struct sched_param param;
vm_thread_linux_schedparams* linux_params = (vm_thread_linux_schedparams*)params;
/* check error(s) */
if (!thread || !linux_params)
return 0;
if (thread->is_valid)
{
vm_mutex_lock(&thread->access_mut);
param.sched_priority = linux_params->priority;
i_res = !pthread_setschedparam(thread->handle, linux_params->schedtype, ¶m);
vm_mutex_unlock(&thread->access_mut);
}
return i_res;
}
开发者ID:ph0b,项目名称:MediaSDK,代码行数:19,代码来源:vm_thread_linux32.c
示例20: 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);
}
}
开发者ID:Drakesinger,项目名称:ArxLibertatis,代码行数:19,代码来源:Thread.cpp
注:本文中的pthread_setschedparam函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论