当前位置: 首页>>代码示例>>C++>>正文


C++ pthread_setschedparam函数代码示例

本文整理汇总了C++中pthread_setschedparam函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_setschedparam函数的具体用法?C++ pthread_setschedparam怎么用?C++ pthread_setschedparam使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pthread_setschedparam函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, &param);
#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, &param) != 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, &param) != 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, &param) != 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, &param) == 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, &param);
        }
    }
#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 = &target;
	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, &param)) {
        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, &param);
		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, &param);

	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, &param);
	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, &param);
	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(), &currentPolicy, &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


注:本文中的pthread_setschedparam函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。