File tree Expand file tree Collapse file tree 7 files changed +22
-9
lines changed Expand file tree Collapse file tree 7 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ class TPosixThread : public TThreadImp {
4040
4141 virtual Int_t Join (TThread *th, void **ret);
4242 virtual Long_t SelfId ();
43- virtual Int_t Run (TThread *th);
43+ virtual Int_t Run (TThread *th, const int affinity = - 1 );
4444
4545 virtual Int_t Kill (TThread *th);
4646 virtual Int_t SetCancelOff ();
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ friend class TJoinHelper;
122122 virtual ~TThread ();
123123
124124 Int_t Kill ();
125- Int_t Run (void *arg = nullptr );
125+ Int_t Run (void *arg = nullptr , const int affinity = - 1 );
126126 void SetPriority (EPriority pri);
127127 void Delete (Option_t *option=" " ) { TObject::Delete (option); }
128128 EPriority GetPriority () const { return fPriority ; }
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ class TThreadImp : public TObject {
3535
3636 virtual Int_t Join (TThread *th, void **ret) = 0;
3737 virtual Long_t SelfId () = 0;
38- virtual Int_t Run (TThread *th) = 0;
38+ virtual Int_t Run (TThread *th, const int affinity = - 1 ) = 0;
3939
4040 virtual Int_t Kill (TThread *th) = 0;
4141 virtual Int_t SetCancelOff () = 0;
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ class TWin32Thread : public TThreadImp {
3535
3636 virtual Int_t Join (TThread *th, void **ret);
3737 virtual Long_t SelfId ();
38- virtual Int_t Run (TThread *th);
38+ virtual Int_t Run (TThread *th, const int affinity = - 1 );
3939
4040 virtual Int_t Kill (TThread *th);
4141
Original file line number Diff line number Diff line change 2020#include " TPosixThread.h"
2121
2222#include " TThread.h"
23+ #include < sched.h>
2324
2425ClassImp (TPosixThread);
2526
@@ -28,13 +29,20 @@ ClassImp(TPosixThread);
2829// / Create a pthread. Returns 0 on success, otherwise an error number will
2930// / be returned.
3031
31- Int_t TPosixThread::Run (TThread *th)
32+ Int_t TPosixThread::Run (TThread *th, const int affinity )
3233{
3334 int det;
3435 pthread_t id;
3536 pthread_attr_t *attr = new pthread_attr_t ;
3637
3738 pthread_attr_init (attr);
39+
40+ if (affinity >= 0 ) {
41+ cpu_set_t cpuset;
42+ CPU_ZERO (&cpuset);
43+ CPU_SET (affinity, &cpuset);
44+ pthread_attr_setaffinity_np (attr, sizeof (cpu_set_t ), &cpuset);
45+ }
3846
3947 // Set detach state
4048 det = (th->fDetached ) ? PTHREAD_CREATE_DETACHED : PTHREAD_CREATE_JOINABLE;
Original file line number Diff line number Diff line change @@ -562,18 +562,21 @@ Long_t TThread::SelfId()
562562// //////////////////////////////////////////////////////////////////////////////
563563// / Start the thread. This starts the static method TThread::Function()
564564// / which calls the user function specified in the TThread ctor with
565- // / the arg argument. Returns 0 on success, otherwise an error number will
565+ // / the arg argument.
566+ // / If affinity is specified (>=0), a CPU affinity will be associated
567+ // / with the current thread.
568+ // / Returns 0 on success, otherwise an error number will
566569// / be returned.
567570
568- Int_t TThread::Run (void *arg)
571+ Int_t TThread::Run (void *arg, const int affinity )
569572{
570573 if (arg) fThreadArg = arg;
571574
572575 SetComment (" Run: MainInternalMutex locking" );
573576 ThreadInternalLock ();
574577 SetComment (" Run: MainMutex locked" );
575578
576- int iret = fgThreadImp->Run (this );
579+ int iret = fgThreadImp->Run (this , affinity );
577580
578581 fState = iret ? kInvalidState : kRunningState ;
579582
Original file line number Diff line number Diff line change @@ -30,12 +30,14 @@ ClassImp(TWin32Thread);
3030// / Win32 threads -- spawn new thread (like pthread_create).
3131// / Win32 has a thread handle in addition to the thread ID.
3232
33- Int_t TWin32Thread::Run (TThread *th)
33+ Int_t TWin32Thread::Run (TThread *th, const int affinity )
3434{
3535 DWORD dwThreadId;
3636 HANDLE hHandle = CreateThread (0 , 0 ,
3737 (LPTHREAD_START_ROUTINE)&TThread::Function,
3838 th, 0 , (DWORD*)&dwThreadId);
39+ if (affinity >= 0 )
40+ Warning (" Run" , " Affinity setting not yet implemented on Win32" );
3941 if (th->fDetached ) {
4042 ::CloseHandle (hHandle);
4143 th->fHandle = 0L ;
You can’t perform that action at this time.
0 commit comments