Exemplo n.º 1
0
		//--------------------------------------------------------------------------
		// Set thread scheduling parameters.  Unfortunately on Linux, there's no
		// good way to set this, as Win32Thread_setschedparam is mostly a no-op.
		//
		static int SetThreadSchedulingParams(Thread *data) {
			
			Thread *thread = static_cast<Thread *>(data);

			Win32ThreadPrivateData *pd =
				static_cast<Win32ThreadPrivateData *>(thread->_prvData);

			int prio = THREAD_PRIORITY_NORMAL;

			switch(thread->getSchedulePriority()) {
			case Thread::PRIORITY_MAX:
				prio = THREAD_PRIORITY_HIGHEST;
				break;
			case Thread::PRIORITY_HIGH:
				prio = THREAD_PRIORITY_ABOVE_NORMAL;
				break;
			case Thread::PRIORITY_NOMINAL:
				prio = THREAD_PRIORITY_NORMAL;
				break;   
			case Thread::PRIORITY_LOW:
				prio = THREAD_PRIORITY_BELOW_NORMAL;
				break;       
			case Thread::PRIORITY_MIN:
				prio = THREAD_PRIORITY_IDLE;
				break;   
			}
			int status = SetThreadPriority( pd->tid , prio);
			PrintThreadSchedulingInfo(thread);   

			return status!=0;
		};
Exemplo n.º 2
0
        //--------------------------------------------------------------------------
        // Set thread scheduling parameters.
        // Note that time-critical priority is ommited :
        // 1) It's not sensible thing to do
        // 2) there's no enum for that in Thread interface
        // Also, on Windows, effective thread priority is :
        // process priority (manipulated with Get/SetProrityClass) + thread priority (here).
        //
        //
        static int SetThreadSchedulingParams(Thread *thread) {

            Win32ThreadPrivateData *pd =
                static_cast<Win32ThreadPrivateData *>(thread->_prvData);

            int prio = THREAD_PRIORITY_NORMAL;

            switch(thread->getSchedulePriority()) {
            case Thread::THREAD_PRIORITY_MAX:
                prio = THREAD_PRIORITY_HIGHEST;
                break;
            case Thread::THREAD_PRIORITY_HIGH:
                prio = THREAD_PRIORITY_ABOVE_NORMAL;
                break;
            case Thread::THREAD_PRIORITY_NOMINAL:
                prio = THREAD_PRIORITY_NORMAL;
                break;
            case Thread::THREAD_PRIORITY_LOW:
                prio = THREAD_PRIORITY_BELOW_NORMAL;
                break;
            case Thread::THREAD_PRIORITY_MIN:
                prio = THREAD_PRIORITY_IDLE;
                break;
            }

            int status = SetThreadPriority( pd->tid.get(), prio);

            if(getenv("OUTPUT_THREADLIB_SCHEDULING_INFO") != 0)
                PrintThreadSchedulingInfo(thread);

            return status!=0;
        };
Exemplo n.º 3
0
    //--------------------------------------------------------------------------
    // Set thread scheduling parameters.  Unfortunately on Linux, there's no
    // good way to set this, as pthread_setschedparam is mostly a no-op.
    //
    static int SetThreadSchedulingParams(Thread *thread)
    {

        int status = 0;

#ifdef ALLOW_PRIORITY_SCHEDULING // [

        if(sysconf(_POSIX_THREAD_PRIORITY_SCHEDULING))
        {

            int th_policy;
            int max_priority, nominal_priority, min_priority;
            sched_param th_param;
            pthread_getschedparam(thread->getProcessId(),
                      &th_policy, &th_param);

#ifndef __linux__

            switch(thread->getSchedulePolicy())
            {

                case Thread::THREAD_SCHEDULE_FIFO:
                th_policy = SCHED_FIFO;
                break;

                case Thread::THREAD_SCHEDULE_ROUND_ROBIN:
                th_policy = SCHED_RR;
                break;

                case Thread::THREAD_SCHEDULE_TIME_SHARE:
                th_policy = SCHED_OTHER;
                break;

                default:
#ifdef __sgi
                th_policy = SCHED_RR;
#else
                th_policy = SCHED_FIFO;
#endif
                break;
            };

#else
            th_policy = SCHED_OTHER;  // Must protect linux from realtime.
#endif

#ifdef __linux__

            max_priority = 0;
            min_priority = 20;
            nominal_priority = (max_priority + min_priority)/2;

#else

            max_priority = sched_get_priority_max(th_policy);
            min_priority = sched_get_priority_min(th_policy);
            nominal_priority = (max_priority + min_priority)/2;

#endif

            switch(thread->getSchedulePriority())
            {

                case Thread::THREAD_PRIORITY_MAX:
                    th_param.sched_priority = max_priority;
                    break;

                case Thread::THREAD_PRIORITY_HIGH:
                    th_param.sched_priority = (max_priority + nominal_priority)/2;
                    break;

                case Thread::THREAD_PRIORITY_NOMINAL:
                    th_param.sched_priority = nominal_priority;
                    break;

                case Thread::THREAD_PRIORITY_LOW:
                    th_param.sched_priority = (min_priority + nominal_priority)/2;
                    break;

                case Thread::THREAD_PRIORITY_MIN:
                    th_param.sched_priority = min_priority;
                    break;

                default:
                    th_param.sched_priority = max_priority;
                    break;

            }

            status = pthread_setschedparam(thread->getProcessId(),
                           th_policy,
                           &th_param);


            if(getenv("OUTPUT_THREADLIB_SCHEDULING_INFO") != 0)
            PrintThreadSchedulingInfo(thread);

        }

#endif // ] ALLOW_PRIORITY_SCHEDULING

    return status;
    };