Alexandre Julliard : server: Allow changing a thread affinity before it is initialized.

Alexandre Julliard julliard at winehq.org
Tue Feb 2 10:45:31 CST 2010


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Feb  2 15:58:02 2010 +0100

server: Allow changing a thread affinity before it is initialized.

---

 server/thread.c |   28 ++++++++++++++--------------
 server/thread.h |    2 +-
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/server/thread.c b/server/thread.c
index b50193a..148ca3b 100644
--- a/server/thread.c
+++ b/server/thread.c
@@ -407,13 +407,9 @@ struct thread *get_thread_from_pid( int pid )
     return NULL;
 }
 
-void set_thread_affinity( struct thread *thread, affinity_t affinity )
+int set_thread_affinity( struct thread *thread, affinity_t affinity )
 {
-    if ((affinity & thread->process->affinity) != affinity)
-    {
-        set_error( STATUS_INVALID_PARAMETER );
-        return;
-    }
+    int ret = 0;
 #ifdef HAVE_SCHED_SETAFFINITY
     if (thread->unix_tid != -1)
     {
@@ -425,15 +421,11 @@ void set_thread_affinity( struct thread *thread, affinity_t affinity )
         for (i = 0, mask = 1; mask; i++, mask <<= 1)
             if (affinity & mask) CPU_SET( i, &set );
 
-        if (!sched_setaffinity( thread->unix_tid, sizeof(set), &set ))
-            thread->affinity = affinity;
-        else
-            file_set_error();
+        ret = sched_setaffinity( thread->unix_tid, sizeof(set), &set );
     }
-    else set_error( STATUS_ACCESS_DENIED );
-#else
-    thread->affinity = affinity;
 #endif
+    if (!ret) thread->affinity = affinity;
+    return ret;
 }
 
 #define THREAD_PRIORITY_REALTIME_HIGHEST 6
@@ -460,7 +452,14 @@ static void set_thread_info( struct thread *thread,
             set_error( STATUS_INVALID_PARAMETER );
     }
     if (req->mask & SET_THREAD_INFO_AFFINITY)
-        set_thread_affinity( thread, req->affinity );
+    {
+        if ((req->affinity & thread->process->affinity) != req->affinity)
+            set_error( STATUS_INVALID_PARAMETER );
+        else if (thread->state == TERMINATED)
+            set_error( STATUS_ACCESS_DENIED );
+        else if (set_thread_affinity( thread, req->affinity ))
+            file_set_error();
+    }
     if (req->mask & SET_THREAD_INFO_TOKEN)
         security_set_thread_token( thread, req->token );
 }
@@ -1158,6 +1157,7 @@ DECL_HANDLER(init_thread)
         generate_debug_event( current, CREATE_THREAD_DEBUG_EVENT, &req->entry );
     }
     debug_level = max( debug_level, req->debug_level );
+    set_thread_affinity( current, current->affinity );
 
     reply->pid     = get_process_id( process );
     reply->tid     = get_thread_id( current );
diff --git a/server/thread.h b/server/thread.h
index 90f6061..1e95732 100644
--- a/server/thread.h
+++ b/server/thread.h
@@ -118,7 +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 );
+extern int set_thread_affinity( struct thread *thread, affinity_t affinity );
 
 /* ptrace functions */
 




More information about the wine-cvs mailing list