本文整理汇总了C++中pthread_attr_getschedparam函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_attr_getschedparam函数的具体用法?C++ pthread_attr_getschedparam怎么用?C++ pthread_attr_getschedparam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pthread_attr_getschedparam函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pthread_attr_init
TCGvoid TCGClient::AddThreadPriority()
{
#ifdef ANDROID
#if 0 /* Add thread priority */
pthread_attr_t attr;
TCGbool policy;
TCGbool rs;
struct sched_param param;
TCGbool maxThreadPriority;
rs = pthread_attr_init(&attr);
pthread_attr_getschedpolicy(&attr, &policy);
if (policy != SCHED_RR)
{
pthread_attr_setschedpolicy(&attr, SCHED_RR);
}
maxThreadPriority = sched_get_priority_max(SCHED_RR);
rs = pthread_attr_getschedparam(&attr, ¶m);
policy = param.sched_priority;
if (policy < maxThreadPriority)
{
param.sched_priority = maxThreadPriority;
pthread_attr_setschedparam(&attr, ¶m);
rs = pthread_attr_getschedparam(&attr, ¶m);
}
#endif
#endif
}
示例2: pthread_attr_init
void CPosixThreadImpl::start(IRhoRunnable *pRunnable, IRhoRunnable::EPriority ePriority)
{
pthread_attr_t attr;
int return_val = pthread_attr_init(&attr);
//return_val = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
RHO_ASSERT(!return_val);
if ( ePriority != IRhoRunnable::epNormal)
{
sched_param param;
return_val = pthread_attr_getschedparam (&attr, ¶m);
param.sched_priority = ePriority == IRhoRunnable::epLow ? 20 : 100; //TODO: sched_priority
return_val = pthread_attr_setschedparam (&attr, ¶m);
}
#ifdef __SYMBIAN32__
size_t stacksize = 80000;
pthread_attr_setstacksize(&attr, stacksize);
#endif
int thread_error = pthread_create(&m_thread, &attr, &runProc, pRunnable);
return_val = pthread_attr_destroy(&attr);
RHO_ASSERT(!return_val);
RHO_ASSERT(thread_error==0);
}
示例3: httpreq_init
gm_Bool
httpreq_init(int port, int boost_prio)
{
char portnum[8];
int i;
pthread_attr_t att;
struct sched_param sched;
sprintf(portnum,"%d",port);
gSock = slisten(portnum);
if (gSock < 1) {
/* failed to open listening socket */
MON_SEND_2(MON_ERR,"Socket listen failed: %s\n", strerror(errno));
return gm_False;
/* NOTREACHED */
}
i = 1;
if (setsockopt(gSock, SOL_SOCKET, SO_REUSEADDR, (const char *)&i, sizeof(int))
!= 0) {
MON_SEND_2(MON_ERR,"setsockopt SO_REUSEADDR: %s", strerror(errno));
}
i = 0;
if (setsockopt(gSock, SOL_SOCKET, SO_KEEPALIVE, (const char *)&i, sizeof(int))
!= 0) {
MON_SEND_2(MON_ERR,"setsockopt SO_KEEPALIVE: %s", strerror(errno));
}
MON_SEND_2(MON_LOGGING,"(HTTP): listening on port %d\n", port);
n_httpreqs = 1;
/* spawn a local worker thread */
THR_OP("HTTP thread attrs init", pthread_attr_init(&att));
THR_OP("HTTP set global scope",
pthread_attr_setscope(&att, PTHREAD_SCOPE_SYSTEM));
THR_OP("HTTP get sched params",
pthread_attr_getschedparam(&att, &sched));
#ifdef _MIT_POSIX_THREADS
sched.prio += boost_prio;
#else
sched.sched_priority += boost_prio;
#endif
THR_OP("HTTP boost prio",
pthread_attr_setschedparam(&att, &sched));
MON_SEND_2(MON_LOGGING,"Boosting HTTP accept() thread prio by %d\n",
boost_prio);
THR_OP("Thread create HTTP",
pthread_create(&thr_http, (pthread_attr_t *)&att,
http_eventloop_proc, (void *)NULL));
proxy_debug_2(DBG_HTTP, "Spawned HTTP worker thread\n");
return gm_True;
}
示例4: start_thread_TRIGGER
int start_thread_TRIGGER(struct radclock_handle *handle)
{
int err;
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
struct sched_param sched;
/*
* Increase the priority of that particular thread to improve the accuracy
* of the packet sender
*/
err = pthread_attr_getschedparam (&thread_attr, &sched);
sched.sched_priority = sched_get_priority_max(SCHED_FIFO);
err = pthread_attr_setschedparam (&thread_attr, &sched);
pthread_attr_setschedpolicy(&thread_attr, SCHED_FIFO);
verbose(LOG_NOTICE, "Starting trigger thread");
err = pthread_create(&(handle->threads[PTH_TRIGGER]), &thread_attr,
thread_trigger, (void *)(handle));
if (err)
verbose(LOG_ERR, "pthread_create() returned error number %d", err);
return (err);
}
示例5: defined
void CPosixThreadImpl::start(IRhoRunnable *pRunnable, IRhoRunnable::EPriority ePriority)
{
#if defined(OS_ANDROID)
// Android has no pthread_condattr_xxx API
pthread_cond_init(&m_condSync, NULL);
#else
pthread_condattr_t sync_details;
pthread_condattr_init(&sync_details);
pthread_cond_init(&m_condSync, &sync_details);
pthread_condattr_destroy(&sync_details);
#endif
pthread_attr_t attr;
int return_val = pthread_attr_init(&attr);
return_val = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
RHO_ASSERT(!return_val);
if ( ePriority != IRhoRunnable::epNormal)
{
sched_param param;
return_val = pthread_attr_getschedparam (&attr, ¶m);
param.sched_priority = ePriority == IRhoRunnable::epLow ? 20 : 100; //TODO: sched_priority
return_val = pthread_attr_setschedparam (&attr, ¶m);
}
int thread_error = pthread_create(&m_thread, &attr, &runProc, pRunnable);
return_val = pthread_attr_destroy(&attr);
RHO_ASSERT(!return_val);
RHO_ASSERT(thread_error==0);
}
示例6: forward_create_thread
static int forward_create_thread(pthread_t *tid, thread_param_t *arg)
{
int t;
pthread_attr_t attr;
struct sched_param param;
pthread_attr_init(&attr);
pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
pthread_attr_setschedpolicy(&attr, DEF_SCHED_POLICY);
pthread_attr_getschedparam(&attr, ¶m);
param.sched_priority = DEF_PRIORITY;
pthread_attr_setschedparam(&attr, ¶m);
for (t = 0; t < NUM_THREADS; t++) {
if (pthread_create(&tid[t], &attr, forward_thread, (void *) &arg[t])) {
error_printf("forward_create_thread failed\n");
return -1;
}
}
pthread_attr_destroy(&attr);
return 0;
}
示例7: thread_createwithpriority
static int thread_createwithpriority(pthread_t *tid,int threadpriority,void *(*func)(void *),void *arg)
{
//pthread_t tid;
pthread_attr_t tattr;
struct sched_param param;
int ret;
int newprio = threadpriority;//20;
// initialized with default attributes
ret = pthread_attr_init(&tattr);
// safe to get existing scheduling param
ret = pthread_attr_getschedparam(&tattr, ¶m);
// set the priority; others are unchanged
//liqapp_log("thread schedparam=%i (current)",param.sched_priority);
param.sched_priority = newprio;
// setting the new scheduling param
ret = pthread_attr_setschedparam(&tattr, ¶m);
// with new priority specified
ret = pthread_create(tid, &tattr, func, arg);
// ret = pthread_create(tid, NULL, func, arg);
return ret;
}
示例8: g_thread_create_posix_impl
static void
g_thread_create_posix_impl (GThreadFunc thread_func,
gpointer arg,
gulong stack_size,
gboolean joinable,
gboolean bound,
GThreadPriority priority,
gpointer thread)
{
pthread_attr_t attr;
g_return_if_fail (thread_func);
posix_check_for_error (pthread_attr_init (&attr));
#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
if (stack_size)
{
stack_size = MAX (g_thread_min_stack_size, stack_size);
posix_check_for_error (pthread_attr_setstacksize (&attr, stack_size));
}
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
#ifdef PTHREAD_SCOPE_SYSTEM
if (bound)
/* No error check here, because some systems can't do it and we
* simply don't want threads to fail because of that. */
pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
#endif /* PTHREAD_SCOPE_SYSTEM */
#ifdef G_THREADS_IMPL_POSIX
posix_check_for_error (pthread_attr_setdetachstate (&attr,
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
#endif /* G_THREADS_IMPL_POSIX */
#ifdef HAVE_PRIORITIES
# ifdef G_THREADS_IMPL_POSIX
{
struct sched_param sched;
posix_check_for_error (pthread_attr_getschedparam (&attr, &sched));
sched.sched_priority = g_thread_map_priority (priority);
posix_check_for_error (pthread_attr_setschedparam (&attr, &sched));
}
# else /* G_THREADS_IMPL_DCE */
posix_check_for_error
(pthread_attr_setprio (&attr, g_thread_map_priority (priority)));
# endif /* G_THREADS_IMPL_DCE */
#endif /* HAVE_PRIORITIES */
posix_check_for_error (pthread_create (thread, &attr,
(void* (*)(void*))thread_func,
arg));
posix_check_for_error (pthread_attr_destroy (&attr));
#ifdef G_THREADS_IMPL_DCE
if (!joinable)
posix_check_for_error (pthread_detach (thread));
#endif /* G_THREADS_IMPL_DCE */
}
示例9: InitThread
int InitThread(pthread_t *threadId, int prio, void *(*func)(void *), void *param){
pthread_attr_t attr;
sched_param sched;
if(pthread_attr_init(&attr) != EOK)
return -1;
if(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) != EOK)
return -1;
if(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != EOK)
return -1;
if(pthread_attr_setschedpolicy(&attr, SCHED_FIFO) != EOK)
return -1;
if(pthread_attr_getschedparam(&attr, &sched) != EOK)
return -1;
sched.sched_priority = prio;
if(pthread_attr_setschedparam(&attr, &sched) != EOK)
return -1;
if(pthread_create(threadId, &attr, func, param) != EOK)
return -1;
if(pthread_attr_destroy(&attr) != 0)
return -1;
return 1;
}
示例10: clone_attributes
void
clone_attributes(pthread_attr_t *new_attr, pthread_attr_t *old_attr)
{
struct sched_param param;
void *addr;
size_t size;
int value;
(void) pthread_attr_init(new_attr);
if (old_attr != NULL) {
(void) pthread_attr_getstack(old_attr, &addr, &size);
/* don't allow a non-NULL thread stack address */
(void) pthread_attr_setstack(new_attr, NULL, size);
(void) pthread_attr_getscope(old_attr, &value);
(void) pthread_attr_setscope(new_attr, value);
(void) pthread_attr_getinheritsched(old_attr, &value);
(void) pthread_attr_setinheritsched(new_attr, value);
(void) pthread_attr_getschedpolicy(old_attr, &value);
(void) pthread_attr_setschedpolicy(new_attr, value);
(void) pthread_attr_getschedparam(old_attr, ¶m);
(void) pthread_attr_setschedparam(new_attr, ¶m);
(void) pthread_attr_getguardsize(old_attr, &size);
(void) pthread_attr_setguardsize(new_attr, size);
}
/* make all pool threads be detached threads */
(void) pthread_attr_setdetachstate(new_attr, PTHREAD_CREATE_DETACHED);
}
示例11: SetThreadPriority
void NONS_Thread::call(NONS_ThreadedFunctionPointer function,void *data,bool give_highest_priority){
if (this->called)
return;
threadStruct *ts=new threadStruct;
ts->f=function;
ts->d=data;
#if NONS_SYS_WINDOWS
this->thread=CreateThread(0,0,(LPTHREAD_START_ROUTINE)runningThread,ts,0,0);
if (give_highest_priority)
SetThreadPriority(this->thread,THREAD_PRIORITY_HIGHEST);
#elif NONS_SYS_UNIX
pthread_attr_t attr,
*pattr=0;
if (give_highest_priority){
pattr=&attr;
pthread_attr_init(pattr);
sched_param params;
pthread_attr_getschedparam(pattr,¶ms);
int policy;
pthread_attr_getschedpolicy(pattr,&policy);
params.sched_priority=sched_get_priority_max(policy);
pthread_attr_setschedparam(pattr,¶ms);
}
pthread_create(&this->thread,pattr,runningThread,ts);
if (give_highest_priority)
pthread_attr_destroy(pattr);
#elif NONS_SYS_PSP
this->thread=SDL_CreateThread(runningThread,ts);
#endif
this->called=1;
}
示例12: test_schedparam
int test_schedparam(pthread_attr_t * attr, int prio, int err_number){
struct sched_param param;
param.sched_priority = prio;
errno = 0;
pthread_attr_setschedparam(attr, ¶m);
if ( err_number != errno ){
if ( errno == 0 ){
printf("expected errno %d\n", errno);
} else {
printf("prio %d ", prio);
fflush(stdout);
perror("failed to set");
}
return -1;
}
if ( errno == 0 ){
if ( pthread_attr_getschedparam(attr, ¶m) < 0 ){
fflush(stdout);
perror("failed to get");
return -1;
}
if ( param.sched_priority != prio ){
printf("failed to set/get (%d != %d)\n", param.sched_priority, prio);
return -1;
}
}
return 0;
}
示例13: throw
int
Thread::getPriority() const
throw (IllegalThreadStateException)
{
if(m_thread_state == TIDTHR_ERROR){
throw IllegalThreadStateException
("Thread::getPriority() Invalid Object");
}
sched_param param;
int policy;
if(m_thread_state != TIDTHR_CREATED) {
if(pthread_getschedparam(m_thread_id.value(),&policy, ¶m)) {
return param.sched_priority;
}
}
// else the thread is not active, return the Thread creation priority
const pthread_attr_t* attr =
(m_thread_attributes == NULL) ?
m_thread_group->getAttributes() : m_thread_attributes;
pthread_attr_getschedparam(attr, ¶m);
return param.sched_priority;
}
示例14: display_pthread_attr
static void display_pthread_attr (pthread_attr_t *attr, char *prefix)
{
int s, i;
size_t v;
void *stkaddr;
struct sched_param sp;
s = pthread_attr_getdetachstate (attr, &i);
if (s != 0)
handle_error_en (s, "pthread_attr_getdetachstate");
printf ("%sDetach state = %s\n", prefix,
(i == PTHREAD_CREATE_DETACHED)
? "PTHREAD_CREATE_DETACHED"
: (i == PTHREAD_CREATE_JOINABLE) ? "PTHREAD_CREATE_JOINABLE"
: "???");
s = pthread_attr_getscope (attr, &i);
if (s != 0)
handle_error_en (s, "pthread_attr_getscope");
printf ("%sScope = %s\n", prefix,
(i == PTHREAD_SCOPE_SYSTEM)
? "PTHREAD_SCOPE_SYSTEM"
: (i == PTHREAD_SCOPE_PROCESS) ? "PTHREAD_SCOPE_PROCESS"
: "???");
s = pthread_attr_getinheritsched (attr, &i);
if (s != 0)
handle_error_en (s, "pthread_attr_getinheritsched");
printf ("%sInherit scheduler = %s\n", prefix,
(i == PTHREAD_INHERIT_SCHED)
? "PTHREAD_INHERIT_SCHED"
: (i == PTHREAD_EXPLICIT_SCHED) ? "PTHREAD_EXPLICIT_SCHED"
: "???");
s = pthread_attr_getschedpolicy (attr, &i);
if (s != 0)
handle_error_en (s, "pthread_attr_getschedpolicy");
printf ("%sScheduling policy = %s\n", prefix,
(i == SCHED_OTHER)
? "SCHED_OTHER"
: (i == SCHED_FIFO) ? "SCHED_FIFO" : (i == SCHED_RR) ? "SCHED_RR"
: "???");
s = pthread_attr_getschedparam (attr, &sp);
if (s != 0)
handle_error_en (s, "pthread_attr_getschedparam");
printf ("%sScheduling priority = %d\n", prefix, sp.sched_priority);
s = pthread_attr_getguardsize (attr, &v);
if (s != 0)
handle_error_en (s, "pthread_attr_getguardsize");
printf ("%sGuard size = %ld bytes\n", prefix, v);
s = pthread_attr_getstack (attr, &stkaddr, &v);
if (s != 0)
handle_error_en (s, "pthread_attr_getstack");
printf ("%sStack address = %p\n", prefix, stkaddr);
printf ("%sStack size = 0x%zx bytes\n", prefix, v);
}
示例15: api_get_thread_priority
static int api_get_thread_priority(pthread_attr_t *attr)
{
struct sched_param param;
int rs = pthread_attr_getschedparam(attr, ¶m);
assert (rs == 0);
printf ("priority = %d\n", param.__sched_priority);
return param.__sched_priority;
}