Juan Lang : server: Setting a process's affinity sets all of its threads' affinities too.

Alexandre Julliard julliard at winehq.org
Wed Sep 30 10:56:09 CDT 2009


Module: wine
Branch: master
Commit: 24036fe13a5bff131640a449c69329040e532871
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=24036fe13a5bff131640a449c69329040e532871

Author: Juan Lang <juan.lang at gmail.com>
Date:   Tue Sep 29 09:15:02 2009 -0700

server: Setting a process's affinity sets all of its threads' affinities too.

---

 dlls/ntdll/tests/info.c |    2 --
 server/process.c        |   14 +++++++++++++-
 server/thread.c         |    7 ++++++-
 server/thread.h         |    1 +
 4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c
index 69126fa..cc25513 100644
--- a/dlls/ntdll/tests/info.c
+++ b/dlls/ntdll/tests/info.c
@@ -946,7 +946,6 @@ static void test_affinity(void)
     /* Setting the process affinity changes the thread affinity to match */
     status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
-    todo_wine
     ok( tbi.AffinityMask == 2, "Unexpected thread affinity\n" );
 
     proc_affinity = (1 << si.dwNumberOfProcessors) - 1;
@@ -955,7 +954,6 @@ static void test_affinity(void)
     /* Resetting the process affinity also resets the thread affinity */
     status = pNtQueryInformationThread( GetCurrentThread(), ThreadBasicInformation, &tbi, sizeof(tbi), NULL );
     ok( status == STATUS_SUCCESS, "Expected STATUS_SUCCESS, got %08x\n", status);
-    todo_wine
     ok( tbi.AffinityMask == (1 << si.dwNumberOfProcessors) - 1,
         "Unexpected thread affinity" );
 }
diff --git a/server/process.c b/server/process.c
index 8df9f39..31d3527 100644
--- a/server/process.c
+++ b/server/process.c
@@ -1095,6 +1095,18 @@ DECL_HANDLER(get_process_info)
     }
 }
 
+static void set_process_affinity( struct process *process, affinity_t affinity )
+{
+    struct thread *thread;
+
+    process->affinity = affinity;
+
+    LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
+    {
+        set_thread_affinity( thread, affinity );
+    }
+}
+
 /* set information about a process */
 DECL_HANDLER(set_process_info)
 {
@@ -1103,7 +1115,7 @@ DECL_HANDLER(set_process_info)
     if ((process = get_process_from_handle( req->handle, PROCESS_SET_INFORMATION )))
     {
         if (req->mask & SET_PROCESS_INFO_PRIORITY) process->priority = req->priority;
-        if (req->mask & SET_PROCESS_INFO_AFFINITY) process->affinity = req->affinity;
+        if (req->mask & SET_PROCESS_INFO_AFFINITY) set_process_affinity( process, req->affinity );
         release_object( process );
     }
 }
diff --git a/server/thread.c b/server/thread.c
index 2ea8929..8b367ca 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -404,6 +404,11 @@ struct thread *get_thread_from_pid( int pid )
     return NULL;
 }
 
+void set_thread_affinity( struct thread *thread, affinity_t affinity )
+{
+    thread->affinity = affinity;
+}
+
 #define THREAD_PRIORITY_REALTIME_HIGHEST 6
 #define THREAD_PRIORITY_REALTIME_LOWEST -7
 
@@ -428,7 +433,7 @@ static void set_thread_info( struct thread *thread,
             set_error( STATUS_INVALID_PARAMETER );
     }
     if (req->mask & SET_THREAD_INFO_AFFINITY)
-        thread->affinity = req->affinity;
+        set_thread_affinity( thread, req->affinity );
     if (req->mask & SET_THREAD_INFO_TOKEN)
         security_set_thread_token( thread, req->token );
 }
diff --git a/server/thread.h b/server/thread.h
index b6c1cf5..90f6061 100644
--- a/server/thread.h
+++ b/server/thread.h
@@ -118,6 +118,7 @@ extern int thread_add_inflight_fd( struct thread *thread, int client, int server
 extern int thread_get_inflight_fd( struct thread *thread, int client );
 extern struct thread_snapshot *thread_snap( int *count );
 extern struct token *thread_get_impersonation_token( struct thread *thread );
+extern void set_thread_affinity( struct thread *thread, affinity_t affinity );
 
 /* ptrace functions */
 




More information about the wine-cvs mailing list