Changeset 5876

Show
Ignore:
Timestamp:
01/03/07 17:49:46
Author:
robert
Message:

Added SetProcessorAffinityOfCurrentThread(int) method to allow one to set
the affinity of the current thread including the main application thread.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenThreads/trunk/include/OpenThreads/Thread

    r5495 r5876  
    3939extern OPENTHREAD_EXPORT_DIRECTIVE int GetNumberOfProcessors(); 
    4040 
     41/** 
     42 *  Set the processor affinity of current thread. 
     43 * 
     44 *  Note, systems where no support exists no affinity will be set, and -1 will be returned.  
     45 * 
     46 */ 
     47extern OPENTHREAD_EXPORT_DIRECTIVE int SetProcessorAffinityOfCurrentThread(unsigned int cpunum); 
    4148 
    4249/** 
  • OpenThreads/trunk/pthread_src/PThread.c++

    r5495 r5876  
    901901#endif     
    902902} 
     903 
     904int OpenThreads::SetProcessorAffinityOfCurrentThread(unsigned int cpunum) 
     905{ 
     906    if (cpunum<0) return -1; 
     907 
     908    Thread* thread = Thread::CurrentThread(); 
     909    if (thread)  
     910    { 
     911        return thread->setProcessorAffinity(cpunum); 
     912    } 
     913    else 
     914    { 
     915    #if defined (__linux__) && defined(CPU_SET) 
     916 
     917        cpu_set_t cpumask; 
     918        CPU_ZERO( &cpumask ); 
     919        CPU_SET( cpunum, &cpumask ); 
     920 
     921        #if defined(COMPILE_USING_TWO_PARAM_sched_setaffinity) 
     922            return sched_setaffinity( 0, &cpumask ); 
     923        #else 
     924            return sched_setaffinity( 0, sizeof(cpumask), &cpumask ); 
     925        #endif 
     926 
     927    #endif 
     928    } 
     929     
     930    return -1; 
     931} 
  • OpenThreads/trunk/sproc_src/SprocThread.c++

    r5495 r5876  
    788788    return 1; 
    789789} 
     790 
     791int OpenThreads::SetProcessorAffinityOfCurrentThread(unsigned int cpunum) 
     792{ 
     793    if (cpunum<0) return -1; 
     794 
     795    Thread* thread = Thread::CurrentThread(); 
     796    if (thread)  
     797    { 
     798        return thread->setProcessorAffinity(cpunum); 
     799    } 
     800    else 
     801    { 
     802        // non op right now, needs implementation. 
     803    } 
     804} 
  • OpenThreads/trunk/win32_src/Win32Thread.cpp

    r5495 r5876  
    646646    return sysInfo.dwNumberOfProcessors; 
    647647} 
     648 
     649int OpenThreads::SetProcessorAffinityOfCurrentThread(unsigned int cpunum) 
     650{ 
     651    if (cpunum<0) return -1; 
     652 
     653    Thread* thread = Thread::CurrentThread(); 
     654    if (thread)  
     655    { 
     656        return thread->setProcessorAffinity(cpunum); 
     657    } 
     658    else 
     659    { 
     660        // non op right now, needs implementation. 
     661    } 
     662}