Esempio n. 1
0
/* 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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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, &param);
	}
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
//==============================================================================
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, &param);
}
Esempio n. 7
0
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);
}
Esempio n. 8
0
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, &param) == 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;
}
Esempio n. 9
0
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, &param) == -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, &param) == -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);

}
Esempio n. 10
0
File: 1-2.c Progetto: 1587/ltp
/* 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;
}
Esempio n. 11
0
/*
 * 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, &param);
    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
}
Esempio n. 12
0
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 */
  }
}
Esempio n. 13
0
    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");
    }
Esempio n. 14
0
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,&param);
    printf("sched_priority:%u\n",param.sched_priority);
    pthread_attr_destroy(&attr);
}
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;
}
Esempio n. 16
0
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;
}
/*
 * Setup the priority map
*/
ClRcT clEoQueueInitialize(void)
{
    ClInt32T minPriority = sched_get_priority_min(CL_EO_SCHED_POLICY);
    ClInt32T maxPriority = sched_get_priority_max(CL_EO_SCHED_POLICY);
    ClInt32T priority=maxPriority;
    ClInt32T decr = 10;
    ClRcT rc = CL_OK;
    register ClInt32T i;

    if(minPriority < 0 )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Error getting minPriority\n"));
        minPriority = 0;
    }
    if(maxPriority < 0 )
    {
        CL_DEBUG_PRINT(CL_DEBUG_ERROR,("Error getting maxPriority\n"));
        maxPriority = 0;
    }

    if(!priority) decr = 0;

    for(i = CL_IOC_HIGH_PRIORITY; i <= CL_IOC_LOW_PRIORITY; ++i)
    {
        gClEoThreadPriorityMap[i] = CL_MAX(priority, 0);
        priority -= decr;
    }

    gClEoThreadPriorityMap[CL_IOC_DEFAULT_PRIORITY] = CL_MAX(priority, 0);
    for(i = CL_IOC_RESERVED_PRIORITY ; i < CL_IOC_MAX_PRIORITIES ; ++i)
        gClEoThreadPriorityMap[i] = CL_MAX(priority, 0);

    rc = clOsalMutexInit(&gClEoQueueMutex);
    CL_ASSERT(rc == CL_OK);

#if defined (EO_QUEUE_STATS)
    signal(SIGUSR2, sigusr2_handler);
#endif

    return rc;
}
Esempio n. 18
0
File: init.c Progetto: ArcEye/rtai-1
void init_linux_scheduler(int sched, int pri)
{
        struct sched_param mysched;

	if(sched != SCHED_RR && sched != SCHED_FIFO) {
                puts("Invalid scheduling scheme");
                exit(1);
	}

	if((pri < sched_get_priority_min(sched)) || (pri > sched_get_priority_max(sched))) {
		puts("Invalid priority");
		exit(2);
	}

        mysched.sched_priority = pri ;
        if( sched_setscheduler( 0, SCHED_FIFO, &mysched ) == -1 ) {
                puts("Error in setting the Linux scheduler");
                perror("errno");
                exit(3);
        }
}
Esempio n. 19
0
void set_real_time_priority(pthread_t thread)
{
	int policy;
	struct sched_param param;

	pthread_getschedparam (thread, &policy, &param);
#ifdef __linux__
	policy = SCHED_FIFO;
	const char* env = getenv("SC_SCHED_PRIO");
	// jack uses a priority of 10 in realtime mode, so this is a good default
	const int defprio = 5;
	const int minprio = sched_get_priority_min(policy);
	const int maxprio = sched_get_priority_max(policy);
	const int prio = env ? atoi(env) : defprio;
	param.sched_priority = sc_clip(prio, minprio, maxprio);
#else
	policy = SCHED_RR;         // round-robin, AKA real-time scheduling
	param.sched_priority = 63; // you'll have to play with this to see what it does
#endif
	pthread_setschedparam (thread, policy, &param);
}
Esempio n. 20
0
	/**
	 * @brief	Sets a new thread priority.
	 *
	 * @note 	Has no effect when USE_CPP11 is defined
	 *
	 * @param	iPriority	the new priority.
	 */
	void Thread::setPriority( EPriority iPriority )
	{
		m_iThreadPriority = iPriority;

#ifndef USE_CPP11
#	ifdef linux
		struct sched_param sp;
		memset(&sp, 0, sizeof(struct sched_param));
	
		int iMin = sched_get_priority_min(0);
		int iMax = sched_get_priority_max(0);
		int iAvg = (iMax + iMin) / 2;

		sp.sched_priority = iAvg + ( iPriority * (iMax - iMin) ) / 4;

		pthread_setschedparam(m_iThreadID, SCHED_RR, &sp);
#	else
		SetThreadPriority(&m_hThread, iPriority);
#	endif
#endif
	}
Esempio n. 21
0
void *thfn(void *arg)
{
   struct sched_param sp;

   (void) arg;

   // cancel me at anytime
   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);

   // go batch, min prio
   sched_getparam(0, &sp);
   sp.sched_priority = sched_get_priority_min(SCHED_BATCH);
   if (sched_setscheduler(0, SCHED_BATCH, &sp))
   {
      perror("setscheduler background");
   }

   while(1);

   return NULL;
}
Esempio n. 22
0
File: 1-1.c Progetto: 1587/ltp
int main(void)
{

	struct timespec interval0;
	struct timespec interval1;
	int result0 = -1;
	int result1 = -1;
	struct sched_param param;

	param.sched_priority = sched_get_priority_min(SCHED_RR);
	if (sched_setscheduler(0, SCHED_RR, &param) == -1) {
		printf("sched_setscheduler failed: %d (%s)\n",
			errno, strerror(errno));
		return PTS_UNRESOLVED;
	}

	interval0.tv_sec = -1;
	interval0.tv_nsec = -1;

	interval1.tv_sec = -1;
	interval1.tv_nsec = -1;

	result0 = sched_rr_get_interval(0, &interval0);
	result1 = sched_rr_get_interval(getpid(), &interval1);

	if (result0 == result1 &&
	    interval0.tv_sec == interval1.tv_sec &&
	    interval0.tv_nsec == interval1.tv_nsec && errno == 0) {
		printf("Test PASSED\n");
		return PTS_PASS;
	} else if (errno != 0) {
		perror("Unexpected error");
		return PTS_FAIL;
	} else {
		printf
		    ("Different results between pid == 0 and pid == getpid().\n");
		return PTS_FAIL;
	}

}
Esempio n. 23
0
    AsyncFileWriter::AsyncFileWriter() {
        pthread_attr_t attr;
        struct sched_param param;

        pending = 0;
        
        // make the thread
        
        param.sched_priority = sched_get_priority_min(SCHED_OTHER);
        
        pthread_attr_init(&attr);

        running = false;
        stop = false;

#ifdef FCAM_PLATFORM_OSX
        // unnamed semaphores not supported on OSX
        char semName[256];
        // Create a unique semaphore name for this TSQueue using its pointer value
        snprintf(semName, 256, "FCam::AsyncFile::sem::%llx", (long long unsigned)this);
        saveQueueSemaphore = sem_open(semName, O_CREAT, 666, 0);
#else
        saveQueueSemaphore = new sem_t;
        sem_init(saveQueueSemaphore, 0, 0);
#endif
        pthread_mutex_init(&saveQueueMutex, NULL);

        if ((errno =
             -(pthread_attr_setschedparam(&attr, &param) ||
               pthread_attr_setschedpolicy(&attr, SCHED_OTHER) ||
#ifndef FCAM_PLATFORM_ANDROID
               pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) ||
#endif
               pthread_create(&thread, &attr, launch_async_file_writer_thread_, this)))) {
            error(Event::InternalError, "Error creating async file writer thread");
            return;
        } else {
            running = true;
        }        
    }
int
pte_setthreadpriority (pthread_t thread, int policy, int priority)
{
  int prio;
  int result;
  pte_thread_t * tp = (pte_thread_t *) thread;

  prio = priority;

  /* Validate priority level. */
  if (prio < sched_get_priority_min (policy) ||
      prio > sched_get_priority_max (policy))
    {
      return EINVAL;
    }

  result = pthread_mutex_lock (&tp->threadLock);

  if (0 == result)
    {
      /* If this fails, the current priority is unchanged. */

      if (0 != pte_osThreadSetPriority(tp->threadId, prio))
        {
          result = EINVAL;
        }
      else
        {
          /*
           * Must record the thread's sched_priority as given,
           * not as finally adjusted.
           */
          tp->sched_priority = priority;
        }

      (void) pthread_mutex_unlock (&tp->threadLock);
    }

  return result;
}
Esempio n. 25
0
static void StartPingPong(void *arg)
{
    pthread_attr_t attr;
    struct sched_param sparam;
    int priority;
    int status;

    // start the thread that runs the state machine.
    status = pthread_attr_init(&attr);
    priority = sched_get_priority_min(SCHED_FIFO);
    if (status != 0)
    {
        printf("pingpong: pthread_attr_init failed, status=%d\n", status);
        goto cleanup;
    }

    status = pthread_attr_setstacksize(&attr, STACKSIZE);
    if (status != 0)
    {
        printf("pingpong: pthread_attr_setstacksize failed, status=%d\n", status);
        goto cleanup;
    }

    sparam.sched_priority = priority;
    status = pthread_attr_setschedparam(&attr,&sparam);
    if (status != OK)
    {
        printf("pingpong: pthread_attr_setschedparam failed, status=%d\n", status);
        goto cleanup;
    }

    status = pthread_create(&machineThread, &attr, machine_thread, (pthread_addr_t)arg);
    if (status != 0)
    {
        printf("pingpong: pthread_create failed, status=%d\n", status);
    }

cleanup:
    printf("pingpong: returning\n");
}
Esempio n. 26
0
int dim_set_scheduler_class(int pclass)
{
#ifdef __linux__
	int ret, prio, p;
	struct sched_param param;

	if(pclass == 0)
	{
		pclass = SCHED_OTHER;
	}
	else if(pclass == 1)
	{
		pclass = SCHED_FIFO;
	}
	else if(pclass == 2)
	{
		pclass = SCHED_RR;
	}
	prio = sched_get_priority_min(pclass);
	ret = pthread_getschedparam(MAIN_thread, &p, &param);
	if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
		param.sched_priority = prio;
	ret = pthread_setschedparam(MAIN_thread, pclass, &param);   
	if(ret)
	  return 0;
	ret = pthread_getschedparam(IO_thread, &p, &param);   
	if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
		param.sched_priority = prio;
	ret = pthread_setschedparam(IO_thread, pclass, &param);   
	if(ret)
	  return 0;
	ret = pthread_getschedparam(ALRM_thread, &p, &param);   
	if( (p == SCHED_OTHER) || (pclass == SCHED_OTHER) )
		param.sched_priority = prio;
	ret = pthread_setschedparam(ALRM_thread, pclass, &param);   
	if(!ret)
	  return 1;
#endif
	return 0;
}
Esempio n. 27
0
bool Thread::setPriority(int prio)
{
#if defined(_WIN32)

	return SetThreadPriority(m_thread_handle, prio);

#else

	struct sched_param sparam;
	int policy;

	if (pthread_getschedparam(m_thread_handle, &policy, &sparam) != 0)
		return false;

	int min = sched_get_priority_min(policy);
	int max = sched_get_priority_max(policy);

	sparam.sched_priority = min + prio * (max - min) / THREAD_PRIORITY_HIGHEST;
	return pthread_setschedparam(m_thread_handle, policy, &sparam) == 0;

#endif
}
Esempio n. 28
0
File: Os.c Progetto: astaykov/ohNet
static void* threadEntrypoint(void* aArg)
{
#ifndef __ANDROID__
    int oldState;
    int status;
#endif
    ThreadData* data = (ThreadData*)aArg;
    assert(data != NULL);

#ifdef ATTEMPT_THREAD_PRIORITIES
    {
        TInt platMin = sched_get_priority_min(kThreadSchedPolicy);
        TInt platMax = sched_get_priority_max(kThreadSchedPolicy);
        // convert the UPnP library's 50 - 150 priority range into
        // an equivalent posix priority
        // ...calculate priority as percentage of library range
        int32_t percent = (((int32_t )data->iPriority - 50) * 100) / (150 - 50);
        // ...calculate native priority as 'percent' through the dest range
        int32_t priority = platMin + ((percent * (platMax - platMin))/100);
        sched_param param;
        param.sched_priority = priority;
        int status = pthread_setschedparam(data->iThread, kThreadSchedPolicy, &param);
        assert(status == 0);
    }
#endif // ATTEMPT_THREAD_PRIORITIES

    // Disable cancellation - we're in a C++ environment, and
    // don't want to rely on pthreads to mess things up for us.
#ifndef __ANDROID__
    status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldState);
    assert(status == 0);
#endif

    //tlsThreadArg = data->iArg;
    pthread_setspecific(gThreadArgKey, data->iArg);
    data->iEntryPoint(data->iArg);

    return NULL;
}
Esempio n. 29
0
    bool set_priority(int priority) {
      int _policy;
      struct sched_param params;

      assert(pthread_getschedparam(native_, &_policy, &params) == 0);
      int max = sched_get_priority_max(_policy);
      int min = sched_get_priority_min(_policy);

      if(min > priority) {
        priority = min;
      }
      else if(max < priority) {
        priority = max;
      }

      params.sched_priority = priority;

      int err = pthread_setschedparam(native_, _policy, &params);
      if(err == ENOTSUP) return false;

      return true;
    }
int main(int ac, char **av)
{

	int lc, ind;		/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* parse standard options */
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		for (ind = 0; ind < TST_TOTAL; ind++) {
			/*
			 * Call sched_get_priority_min(2)
			 */
			TEST(sched_get_priority_min(test_cases[ind].policy));

			if (TEST_RETURN == test_cases[ind].retval) {
				tst_resm(TPASS, "%s Passed",
					 test_cases[ind].desc);
			} else {
				tst_resm(TFAIL|TTERRNO, "%s Failed,"
					 "sched_get_priority_min() returned %ld",
					 test_cases[ind].desc, TEST_RETURN);
			}
		}
	}

	/* cleanup and exit */
	cleanup();

	tst_exit();

}