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


C++ pthread_getschedparam函数代码示例

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


在下文中一共展示了pthread_getschedparam函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PJ_DEF

/*
 * Get the highest priority value available on this system.
 */
PJ_DEF(int) pj_thread_get_prio_max(pj_thread_t *thread)
{
    struct sched_param param;
    int policy;
    int rc;

    rc = pthread_getschedparam(thread->thread, &policy, &param);
    if (rc != 0)
	return -1;

#if defined(_POSIX_PRIORITY_SCHEDULING)
    return sched_get_priority_max(policy);
#elif defined __OpenBSD__
    /* Thread prio min/max are declared in OpenBSD private hdr */
    return 31;
#else
    pj_assert("pj_thread_get_prio_max() not supported!");
    return 0;
#endif
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:23,代码来源:os_core_unix.c

示例2: 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;
}
开发者ID:RikVerschueren,项目名称:AccordionMega,代码行数:41,代码来源:rtaudiomodule.cpp

示例3: defined

bool gcore::Thread::priority(gcore::Thread::Priority prio) {
  if (mRunning) {
    sched_param sched; // = {0, 0};
    int plcy = 0;
    if (pthread_getschedparam((pthread_t)mSelf, &plcy, &sched) == 0) {
#if defined(_POSIX_PRIORITY_SCHEDULING)
      int priomax = sched_get_priority_max(plcy);
      int priomin = sched_get_priority_min(plcy);
#elif defined(PTHREAD_MINPRIORITY) && defined(PTHREAD_MAX_PRIORITY)
      int priomin = PTHREAD_MIN_PRIORITY;
      int priomax = PTHREAD_MAX_PRIORITY;
#else
      int priomin = 0;
      int priomax = 32;
#endif
      int priomed = (priomax + priomin) / 2;
      switch (prio) {
      case PRI_VERY_LOW:
        sched.sched_priority = priomin;
        break;
      case PRI_LOW:
        sched.sched_priority = (priomin + priomed) / 2;
        break;
      case PRI_NORMAL:
        sched.sched_priority = priomed;
        break;
      case PRI_HIGH:
        sched.sched_priority = (priomax + priomed) / 2;
        break;
      case PRI_VERY_HIGH:
        sched.sched_priority = priomax;
        break;
      default:
        sched.sched_priority = priomed;
        break;
      }
      return (pthread_setschedparam((pthread_t)mSelf, plcy, &sched) == 0);
    }
  }
  return false;
}
开发者ID:gatgui,项目名称:gcore,代码行数:41,代码来源:threads.cpp

示例4: pa_make_realtime

/* Make the current thread a realtime thread, and acquire the highest
 * rtprio we can get that is less or equal the specified parameter. If
 * the thread is already realtime, don't do anything. */
int pa_make_realtime(int rtprio) {

#ifdef _POSIX_PRIORITY_SCHEDULING
    struct sched_param sp;
    int r, policy;

    memset(&sp, 0, sizeof(sp));
    policy = 0;

    if ((r = pthread_getschedparam(pthread_self(), &policy, &sp)) != 0) {
        pa_log("pthread_getschedgetparam(): %s", pa_cstrerror(r));
        return -1;
    }

    if (policy == SCHED_FIFO && sp.sched_priority >= rtprio) {
        pa_log_info("Thread already being scheduled with SCHED_FIFO with priority %i.", sp.sched_priority);
        return 0;
    }

    sp.sched_priority = rtprio;
    if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) != 0) {

        while (sp.sched_priority > 1) {
            sp.sched_priority --;

            if ((r = pthread_setschedparam(pthread_self(), SCHED_FIFO, &sp)) == 0) {
                pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i, which is lower than the requested %i.", sp.sched_priority, rtprio);
                return 0;
            }
        }

        pa_log_warn("pthread_setschedparam(): %s", pa_cstrerror(r));
        return -1;
    }

    pa_log_info("Successfully enabled SCHED_FIFO scheduling for thread, with priority %i.", sp.sched_priority);
    return 0;
#else
    return -1;
#endif
}
开发者ID:thewb,项目名称:mokoiax,代码行数:44,代码来源:core-util.c

示例5: benchmark_pthread_setschedparam

void benchmark_pthread_setschedparam(void)
{
  int status;
  int policy;
  struct sched_param param;
  pthread_t thread_ID;

  status = pthread_create(&thread_ID, NULL, test_thread, NULL);
  rtems_test_assert( status == 0 );

  /* make test_thread equal to POSIX_Init() */
  pthread_getschedparam(pthread_self(), &policy, &param);
  pthread_setschedparam(thread_ID, policy, &param);
  /* At this point, we've switched to test_thread */

  /* Back from test_thread, switch to test_thread again */
  param.sched_priority = sched_get_priority_max(policy) - 1;

  benchmark_timer_initialize();
  pthread_setschedparam(thread_ID, policy, &param);
}
开发者ID:Fyleo,项目名称:rtems,代码行数:21,代码来源:init.c

示例6: switch

gcore::Thread::Scheduling gcore::Thread::scheduling() const {
  Scheduling result = SCH_UNKNOWN;
  if (mRunning) {
    sched_param sched; // = {0, 0};
    int plcy = 0;
    if (pthread_getschedparam((pthread_t)mSelf, &plcy, &sched) == 0) {
      switch (plcy) {
      case SCHED_FIFO:
        result = SCH_FIFO;
        break;
      case SCHED_RR:
        result = SCH_RR;
        break;
      default:
        result = SCH_DEFAULT;
        break;
      }
    }
  }
  return result;
}
开发者ID:gatgui,项目名称:gcore,代码行数:21,代码来源:threads.cpp

示例7: coremu_init_sched_core

void coremu_init_sched_core()
{
    int policy;
    CMCore *self;
    struct sched_param param;
    assert(!pthread_getschedparam(pthread_self(), &policy, &param));
    assert(policy == CM_SCHED_POLICY);

    coremu_thread_setpriority(PRIO_PROCESS, 0, avg_prio);
    self = coremu_get_core_self();
    self->tid = coremu_gettid();

    /* display the scheduling info */
    display_thread_sched_attr("CORE thread scheduler settings:");

#ifdef CM_ENABLE_BIND_CORE
    /* bind thread to a specific core */
    //topology_bind_core();
#endif

}
开发者ID:wind15973,项目名称:research,代码行数:21,代码来源:sched.c

示例8: osd_thread_adjust_priority

int osd_thread_adjust_priority(osd_thread *thread, int adjust)
{
#ifdef WIN32
   if (adjust)
      SetThreadPriority(thread->handle, THREAD_PRIORITY_ABOVE_NORMAL);
   else
      SetThreadPriority(thread->handle, GetThreadPriority(GetCurrentThread()));
   return TRUE;
#else
	struct sched_param  sched;
	int                 policy;

	if ( pthread_getschedparam( thread->thread, &policy, &sched ) == 0 )
	{
		sched.sched_priority += adjust;
		if ( pthread_setschedparam(thread->thread, policy, &sched ) == 0)
			return TRUE;
	}
   return FALSE;
#endif
}
开发者ID:libretro,项目名称:mame2014-libretro,代码行数:21,代码来源:sync_retro.c

示例9: benchmark_pthread_getschedparam

void benchmark_pthread_getschedparam(void)
{
  uint32_t            end_time;
  int                 status;
  int                 policy;
  struct sched_param  param;

  benchmark_timer_initialize();
  status = pthread_getschedparam( pthread_self(), &policy, &param );
  end_time = benchmark_timer_read();
  rtems_test_assert( status == 0 );

  put_time(
    "pthread_getschedparam: only case",
    end_time,
    1,        /* Only executed once */
    0,
    0
  );

}
开发者ID:AlexShiLucky,项目名称:rtems,代码行数:21,代码来源:init.c

示例10: func_noise

void* func_noise(void* arg)
{
	Thread* pthr = (Thread*)arg;
	int rc, i, j, policy, tid = gettid();
	struct sched_param schedp;
	cpu_set_t mask;
	CPU_ZERO(&mask);
	CPU_SET(0, &mask);

	rc = sched_setaffinity(0, sizeof(mask), &mask);
	if (rc < 0) {
		 printf("Thread %d: Can't set affinity: %d %s\n", tid, rc, strerror(rc));
		 exit(-1);
	}
	rc = sched_getaffinity(0, sizeof(mask), &mask);

	printf("Noise Thread started %d on CPU %ld\n", pthr->priority, (long)mask.__bits[0]);
	pthread_getschedparam(pthr->pthread, &policy, &schedp);

	while (1) {
		sleep(1);
		printf("Noise Thread running %d\n", pthr->priority);

		for (i = 0; i < 10000; i++) {
			if ((i % 100) == 0) {
				sched_getparam(tid, &schedp);
				policy = sched_getscheduler(tid);
				printf("Noise Thread %d(%d) loop %d pthread pol %d pri %d\n", tid, pthr->priority, i, policy, schedp.sched_priority);
				fflush(NULL);
			}
			pthr->id++;
			for (j = 0; j < 5000; j++) {
				pthread_mutex_lock(&(pthr->mutex));
				pthread_mutex_unlock(&(pthr->mutex));
			}
		}
		pthread_yield();
	}
	return NULL;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:40,代码来源:testpi-3.c

示例11: lx_sched_getparam

long
lx_sched_getparam(uintptr_t pid, uintptr_t param)
{
	int	policy, ret;
	pid_t	s_pid;
	lwpid_t	s_tid;

	struct sched_param sp;

	if (((pid_t)pid < 0) || (param == NULL))
		return (-EINVAL);

	if (lx_lpid_to_spair((pid_t)pid, &s_pid, &s_tid) < 0)
		return (-ESRCH);

	/*
	 * If we're attempting to get information on our own process, we can
	 * get data on a per-thread basis; if not, punt and use the specified
	 * pid.
	 */
	if (s_pid == getpid()) {
		if ((ret = pthread_getschedparam(s_tid, &policy, &sp)) != 0)
			return (-ret);
	} else {
		if (sched_getparam(s_pid, &sp) == -1)
			return (-errno);

		if ((policy = sched_getscheduler(s_pid)) < 0)
			return (-errno);
	}

	/*
	 * Make sure that any non-SCHED_FIFO non-SCHED_RR scheduler is mapped
	 * onto SCHED_OTHER.
	 */
	if (policy != SCHED_FIFO && policy != SCHED_RR)
		policy = SCHED_OTHER;

	return (stol_sparam(policy, &sp, (struct lx_sched_param *)param));
}
开发者ID:maosi66,项目名称:illumos-joyent,代码行数:40,代码来源:sched.c

示例12: hilo

void * hilo(void * arg)
{
    struct sched_param sp;
    int algoritmo;
    
    param * valores = (param * ) arg;
    
    pthread_t tid = pthread_self();
    
    pthread_getschedparam(tid, &algoritmo, &sp);
    printf("Algoritmo = %d, Prioridad = %d \n",
           algoritmo, sp.sched_priority);
    
    algoritmo = SCHED_RR;
    sp.sched_priority = 5;
    
    pthread_setschedparam(tid, algoritmo, &sp);
    printf("Algoritmo = %d, Prioridad = %d \n",
           algoritmo, sp.sched_priority);
    
    
    pthread_setspecific(tsd, (void *) &valores->tid);
    
    int * numero = (int *) pthread_getspecific(tsd);
    
    printf("TSD en %s = %d antes de modificar \n", valores->nombre, *numero);
    
    *numero = rand() % 100;
    
    pthread_setspecific(tsd, (void *) numero);
    
    numero = (int *) pthread_getspecific(tsd);
    
    printf("TSD en %s (%zd) = %d antes de modificar \n",
           valores->nombre,
           tid,
           *numero);
    
    pthread_exit(NULL);
}
开发者ID:vcubells,项目名称:tc2025,代码行数:40,代码来源:main.c

示例13: server_thread_start

  static int server_thread_start () {
    pthread_attr_t thread_attr;
    struct sched_param param;
    int policy, result;

    logd ("server_thread_start thread_state: %d", thread_state);

    if (thread_state == 1) {
      logd ("server_thread_start & thread_state = running");
      return (BT_HC_STATUS_SUCCESS);
    }

    if (thread_state == 2) {
      logd ("server_thread_start & thread_state = not needed and running");
      return (BT_HC_STATUS_SUCCESS);
    }

    thread_state = 1;                                                   // Thread started
    pthread_mutex_init (& server_thread.mutex, NULL);
    pthread_cond_init  (& server_thread.cond, NULL);
    pthread_attr_init  (& thread_attr);

    if (pthread_create (& server_thread.server_thread, & thread_attr, bt_server_thread, NULL) != 0) {
      loge ("server_thread_start pthread_create failed");
      thread_state = 0;
      return (BT_HC_STATUS_FAIL);
    }

    if (pthread_getschedparam (server_thread.server_thread, & policy, & param) == 0) {
      policy = SCHED_NORMAL;
      //param.sched_priority = BTHC_MAIN_THREAD_PRIORITY;
      errno = 0;
      result = pthread_setschedparam (server_thread.server_thread, policy, & param);
      if (result != 0) {
        loge ("server_thread_start pthread_setschedparam failed errno: %d (%s) (%s)", errno, strerror (errno), strerror (result));  // ????
      }
    }
    logd ("server_thread_start done");
    return (BT_HC_STATUS_SUCCESS);
  }
开发者ID:Averroes,项目名称:spirit2_free,代码行数:40,代码来源:bt-ven.c

示例14: dim_get_priority

int dim_get_priority(int threadId, int *prio)
{
#ifdef __linux__
	pthread_t id=MAIN_thread;
	int ret;
	int pclass;
	struct sched_param param;

	if(threadId == 1)
		id = MAIN_thread;
	else if(threadId == 2)
		id = IO_thread;
	else if(threadId == 3)
		id = ALRM_thread;

	ret = pthread_getschedparam(id, &pclass, &param);   
	*prio = param.sched_priority;
	if(!ret)
	  return 1;
#endif
	return 0;
}
开发者ID:larks,项目名称:DIM-FreeRTOS,代码行数:22,代码来源:dim_thr.c

示例15: il_tool_cb_empty_buffer_done

void il_tool_cb_empty_buffer_done(
                            il_comp_t           component_handle,
                            OMX_BUFFERHEADERTYPE*    buffer_done_p)
{
#if 0
    {
        struct sched_param sched_param;
        int    sched_policy;
        int    nice_prio;

        pthread_getschedparam(pthread_self(), &sched_policy, &sched_param);
        ALOG_STATUS("SCHED_OTHER=%d, SCHED_FIFO=%d, SCHED_RR=%d\n", SCHED_OTHER, SCHED_FIFO, SCHED_RR);
        ALOG_STATUS("IL ETB callback thread info: getpriority=%d pthread.policy=%d pthread.sched_priority=%d\n",
                    getpriority(PRIO_PROCESS, gettid()), sched_policy, sched_param.sched_priority);
    }
#endif

    ADM_ASSERT(component_handle != NULL);
    ADM_ASSERT(buffer_done_p != NULL);

    srv_send_il_buffer_msg(component_handle, buffer_done_p, CB_TYPE_BUFFER_EMPTIED);
}
开发者ID:J-Team,项目名称:platform_hardware_ST-Ericsson,代码行数:22,代码来源:ste_adm_omx_tool.c


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