* Removed B_{MIN|MAX}_PRIORITY from OS.h - they were never really intended
as public defines. They are now called THREAD_{MIN|MAX}_SET_PRIORITY to
better reflect what they are for. Minimum priority is now 1, ie. you no
longer can set another thread to the idle priority. This fixes part of
ticket #2959.
* set_thread_priority() will no longer allow to change the priority of the
idle thread to something else. This fixes the rest of ticket #2959.
* Automatic whitespace cleanup in OS.h.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28521 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -303,12 +303,10 @@ typedef struct {
|
||||
#define B_URGENT_PRIORITY 110
|
||||
#define B_REAL_TIME_PRIORITY 120
|
||||
|
||||
#define B_FIRST_REAL_TIME_PRIORITY B_REAL_TIME_DISPLAY_PRIORITY
|
||||
#define B_MIN_PRIORITY B_IDLE_PRIORITY
|
||||
#define B_MAX_PRIORITY B_REAL_TIME_PRIORITY
|
||||
|
||||
#define B_SYSTEM_TIMEBASE 0
|
||||
|
||||
#define B_FIRST_REAL_TIME_PRIORITY B_REAL_TIME_DISPLAY_PRIORITY
|
||||
|
||||
typedef status_t (*thread_func)(void *);
|
||||
#define thread_entry thread_func
|
||||
/* thread_entry is for backward compatibility only! Use thread_func */
|
||||
|
||||
@@ -34,6 +34,9 @@ enum additional_thread_state {
|
||||
// THREAD_STATE_BIRTH // thread is being created
|
||||
};
|
||||
|
||||
#define THREAD_MIN_SET_PRIORITY B_LOWEST_ACTIVE_PRIORITY
|
||||
#define THREAD_MAX_SET_PRIORITY B_REAL_TIME_PRIORITY
|
||||
|
||||
enum team_state {
|
||||
TEAM_STATE_NORMAL, // normal state
|
||||
TEAM_STATE_BIRTH, // being contructed
|
||||
@@ -49,6 +52,7 @@ typedef enum job_control_state {
|
||||
JOB_CONTROL_STATE_DEAD
|
||||
} job_control_state;
|
||||
|
||||
|
||||
struct image; // defined in image.c
|
||||
struct realtime_sem_context; // defined in realtime_sem.cpp
|
||||
struct select_info;
|
||||
|
||||
@@ -873,10 +873,10 @@ set_thread_prio(int argc, char **argv)
|
||||
}
|
||||
|
||||
prio = strtoul(argv[1], NULL, 0);
|
||||
if (prio > B_MAX_PRIORITY)
|
||||
prio = B_MAX_PRIORITY;
|
||||
if (prio < B_MIN_PRIORITY)
|
||||
prio = B_MIN_PRIORITY;
|
||||
if (prio > THREAD_MAX_SET_PRIORITY)
|
||||
prio = THREAD_MAX_SET_PRIORITY;
|
||||
if (prio < THREAD_MIN_SET_PRIORITY)
|
||||
prio = THREAD_MIN_SET_PRIORITY;
|
||||
|
||||
if (argc > 2)
|
||||
id = strtoul(argv[2], NULL, 0);
|
||||
@@ -2502,33 +2502,35 @@ set_thread_priority(thread_id id, int32 priority)
|
||||
int32 oldPriority;
|
||||
|
||||
// make sure the passed in priority is within bounds
|
||||
if (priority > B_MAX_PRIORITY)
|
||||
priority = B_MAX_PRIORITY;
|
||||
if (priority < B_MIN_PRIORITY)
|
||||
priority = B_MIN_PRIORITY;
|
||||
if (priority > THREAD_MAX_SET_PRIORITY)
|
||||
priority = THREAD_MAX_SET_PRIORITY;
|
||||
if (priority < THREAD_MIN_SET_PRIORITY)
|
||||
priority = THREAD_MIN_SET_PRIORITY;
|
||||
|
||||
thread = thread_get_current_thread();
|
||||
if (thread->id == id) {
|
||||
// it's ourself, so we know we aren't in the run queue, and we can manipulate
|
||||
// our structure directly
|
||||
if (thread_is_idle_thread(thread))
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
// It's ourself, so we know we aren't in the run queue, and we can
|
||||
// manipulate our structure directly
|
||||
oldPriority = thread->priority;
|
||||
// note that this might not return the correct value if we are preempted
|
||||
// here, and another thread changes our priority before the next line is
|
||||
// executed
|
||||
// Note that this might not return the correct value if we are
|
||||
// preempted here, and another thread changes our priority before
|
||||
// the next line is executed.
|
||||
thread->priority = thread->next_priority = priority;
|
||||
} else {
|
||||
cpu_status state = disable_interrupts();
|
||||
GRAB_THREAD_LOCK();
|
||||
InterruptsSpinLocker _(gThreadSpinlock);
|
||||
|
||||
thread = thread_get_thread_struct_locked(id);
|
||||
if (thread) {
|
||||
if (thread == NULL)
|
||||
return B_BAD_THREAD_ID;
|
||||
|
||||
if (thread_is_idle_thread(thread))
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
oldPriority = thread->priority;
|
||||
scheduler_set_thread_priority(thread, priority);
|
||||
} else
|
||||
oldPriority = B_BAD_THREAD_ID;
|
||||
|
||||
RELEASE_THREAD_LOCK();
|
||||
restore_interrupts(state);
|
||||
}
|
||||
|
||||
return oldPriority;
|
||||
|
||||
Reference in New Issue
Block a user