server: Only commit SetThreadPriority if new priority is
correct (try 2)
Matt Jones
mattj at google.com
Thu Jul 19 17:28:50 CDT 2007
Ok - I was using DWORD instead of int for min & max which made them
unsigned. I've corrected that now and attached an updated version of
both patches (also corrected my email address in the patch)
Thanks,
Matt
On 7/19/07, Robert Shearman <rob at codeweavers.com> wrote:
> Matt Jones wrote:
> > + if ((req->priority >= min ||
> > + req->priority == THREAD_PRIORITY_IDLE) ||
> > + (req->priority <= max ||
> > + req->priority == THREAD_PRIORITY_TIME_CRITICAL))
> > + thread->priority = req->priority;
> > + }
> >
>
> This doesn't look correct. There should be an && in there instead of one
> of the || operators.
>
> --
> Rob Shearman
>
>
-------------- next part --------------
From e1d7448127d2f1eed7bae1141b365bb61bd25447 Mon Sep 17 00:00:00 2001
From: Matt Jones <mattj at google.com>
Date: Tue, 17 Jul 2007 14:51:14 -0700
Subject: [PATCH] kernel32: Added SetThreadPriority tests, try 2
---
dlls/kernel32/tests/thread.c | 15 +++++++++++++++
1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c
index bbda00e..e6df213 100644
--- a/dlls/kernel32/tests/thread.c
+++ b/dlls/kernel32/tests/thread.c
@@ -588,6 +588,21 @@ #endif
"GetThreadPriority Failed\n");
ok(SetThreadPriority(curthread,0)!=0,"SetThreadPriority Failed\n");
+/* Check that the thread priority is not changed if SetThreadPriority
+ is called with a value outside of the max/min range */
+ SetThreadPriority(curthread,min_priority);
+ SetThreadPriority(curthread,min_priority-1);
+ todo_wine
+ ok(GetThreadPriority(curthread)==min_priority,
+ "GetThreadPriority didn't return min_priority\n");
+
+ SetThreadPriority(curthread,max_priority);
+ SetThreadPriority(curthread,max_priority+1);
+ todo_wine
+ ok(GetThreadPriority(curthread)==max_priority,
+ "GetThreadPriority didn't return max_priority\n");
+
+
/* Check thread priority boost */
if (!pGetThreadPriorityBoost || !pSetThreadPriorityBoost)
return; /* Win9x */
--
1.4.1
-------------- next part --------------
From 40bcdbe07d2f5cc0e5de33512858625f940b9c8c Mon Sep 17 00:00:00 2001
From: Matt Jones <mattj at google.com>
Date: Tue, 17 Jul 2007 14:58:01 -0700
Subject: [PATCH] server: Conform to SetThreadPriority check (only set priority if the new priority is valid), try 2
---
dlls/kernel32/tests/thread.c | 2 --
server/thread.c | 19 ++++++++++++++++++-
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/dlls/kernel32/tests/thread.c b/dlls/kernel32/tests/thread.c
index e6df213..60c801a 100644
--- a/dlls/kernel32/tests/thread.c
+++ b/dlls/kernel32/tests/thread.c
@@ -592,13 +592,11 @@ #endif
is called with a value outside of the max/min range */
SetThreadPriority(curthread,min_priority);
SetThreadPriority(curthread,min_priority-1);
- todo_wine
ok(GetThreadPriority(curthread)==min_priority,
"GetThreadPriority didn't return min_priority\n");
SetThreadPriority(curthread,max_priority);
SetThreadPriority(curthread,max_priority+1);
- todo_wine
ok(GetThreadPriority(curthread)==max_priority,
"GetThreadPriority didn't return max_priority\n");
diff --git a/server/thread.c b/server/thread.c
index 62d50b5..49ecdf4 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -383,12 +383,29 @@ struct thread *get_thread_from_pid( int
return NULL;
}
+#define THREAD_PRIORITY_REALTIME_HIGHEST 6
+#define THREAD_PRIORITY_REALTIME_LOWEST -7
+
/* set all information about a thread */
static void set_thread_info( struct thread *thread,
const struct set_thread_info_request *req )
{
if (req->mask & SET_THREAD_INFO_PRIORITY)
- thread->priority = req->priority;
+ {
+ int max = THREAD_PRIORITY_HIGHEST;
+ int min = THREAD_PRIORITY_LOWEST;
+ if (thread->process->priority == PROCESS_PRIOCLASS_REALTIME)
+ {
+ max = THREAD_PRIORITY_REALTIME_HIGHEST;
+ min = THREAD_PRIORITY_REALTIME_LOWEST;
+ }
+
+ if ((req->priority >= min ||
+ req->priority == THREAD_PRIORITY_IDLE) &&
+ (req->priority <= max ||
+ req->priority == THREAD_PRIORITY_TIME_CRITICAL))
+ thread->priority = req->priority;
+ }
if (req->mask & SET_THREAD_INFO_AFFINITY)
{
if (req->affinity != 1) set_error( STATUS_INVALID_PARAMETER );
--
1.4.1
More information about the wine-devel
mailing list