Changeset 20822

Show
Ignore:
Timestamp:
09/17/07 10:39:32 (1 year ago)
Author:
patrick
Message:

Changed the parameter type for vpr::Thread::setRunOn() back to const int. This
is done to silence a compiler warning and to account for the fact that
non-Windows platforms appear to prefer an int rather than an unsigned int when
doing CPU affinity operations. The CPU value is still clamped to be greater
than or equal to 0, but it is now done using a pre-condition with an exception
rather than by value type.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.h

    r20816 r20822  
    245245   void setPrio(const VPRThreadPriority prio); 
    246246 
    247    void setRunOn(const unsigned int) 
     247   /** 
     248    * Sets the CPU affinity for this thread (the CPU on which this thread 
     249    * will exclusively run). This implementation does nothing. 
     250    * 
     251    * @pre The thread must have been set to be a system-scope thread. The 
     252    *      thread from which this method was invoked must be the same as the 
     253    *      thread spawned by this object. 
     254    * @post The CPU affinity is set or an exception is thrown. 
     255    * 
     256    * @param cpu The CPU on which this thread will run exclusively. This value 
     257    *            is zero-based and therefore must be greater than 0 (zero) and 
     258    *            less than the number of processors available on the computer. 
     259    * 
     260    * @throw vpr::IllegalArgumentException 
     261    *           Thrown if the thread spawned through the use of this object is 
     262    *           not the thread from which this method was invoked. 
     263    * @throw vpr::IllegalArgumentException 
     264    *           Thrown if \p cpu is less than 0. 
     265    * @throw vpr::IllegalArgumentException 
     266    *           Thrown if this is not a system-scope (i.e., global) thread. 
     267    * @throw vpr::Exception 
     268    *           Thrown if the CPU affinity for the running thread could not 
     269    *           be changed. 
     270    * 
     271    * @note Currently, this method does nothing. 
     272    * 
     273    * @since 2.1.6 
     274    */ 
     275   void setRunOn(const int) 
    248276   { 
    249277      /* Do nothing. */ ; 
    250278   } 
    251279 
     280   /** 
     281    * Gets the CPU affinity for this thread (the CPU on which this thread 
     282    * exclusively runs). This implementation does nothing. 
     283    * 
     284    * @pre The thread must have been set to be a system-scope thread, and 
     285    *      a previous affinity must have been set using setRunOn(). The thread 
     286    *      from which this method was invoked must be the same as the thread 
     287    *      spawned by this object. 
     288    * @post The CPU affinity for this thread is returned to the caller. 
     289    * 
     290    * @return The CPU affinity for this thread (posisbly set by a previous 
     291    *         call to setRunOn()). This implementation always returns an 
     292    *         empty vector. 
     293    * 
     294    * @throw vpr::IllegalArgumentException 
     295    *           Thrown if the thread spawned through the use of this object is 
     296    *           not the thread from which this method was invoked. 
     297    * @throw vpr::IllegalArgumentException 
     298    *           Thrown if this is not a system-scope (i.e., global) thread. 
     299    * @throw vpr::Exception 
     300    *           Thrown if the CPU affinity for the running thread could not 
     301    *           be queried. 
     302    * 
     303    * @note Currently, this method does nothing. It always returns an empty 
     304    *       vector. 
     305    * 
     306    * @since 2.1.6 
     307    */ 
    252308   std::vector<unsigned int> getRunOn() const 
    253309   { 
  • juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.cpp

    r20819 r20822  
    383383} 
    384384 
    385 void ThreadPosix::setRunOn(const unsigned int cpu) 
     385void ThreadPosix::setRunOn(const int cpu) 
    386386{ 
    387387   if ( ThreadPosix::self() == this ) 
    388388   { 
     389      if ( cpu < 0 ) 
     390      { 
     391         std::ostringstream msg_stream; 
     392         msg_stream << "Illegal CPU identifier " << cpu << " is less than 0"; 
     393         throw vpr::IllegalArgumentException(msg_stream.str(), VPR_LOCATION); 
     394      } 
     395 
    389396#if defined(VPR_OS_IRIX) 
    390397      if ( mScope == VPR_GLOBAL_THREAD ) 
     
    403410         cpu_set_t cpu_mask; 
    404411         CPU_ZERO(&cpu_mask); 
    405          CPU_SET(static_cast<int>(cpu), &cpu_mask); 
     412         CPU_SET(cpu, &cpu_mask); 
    406413         const int result = sched_setaffinity(0, sizeof(cpu_mask), &cpu_mask); 
    407414 
  • juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.h

    r20816 r20822  
    314314    * 
    315315    * @param cpu The CPU on which this thread will run exclusively. This value 
    316     *            is zero-based and therefore must be less than the number of 
    317     *            processors available on the computer. 
     316    *            is zero-based and therefore must be greater than 0 (zero) and 
     317    *            less than the number of processors available on the computer. 
    318318    * 
    319319    * @throw vpr::IllegalArgumentException 
    320320    *           Thrown if the thread spawned through the use of this object is 
    321321    *           not the thread from which this method was invoked. 
     322    * @throw vpr::IllegalArgumentException 
     323    *           Thrown if \p cpu is less than 0. 
    322324    * @throw vpr::IllegalArgumentException 
    323325    *           Thrown if this is not a system-scope (i.e., global) thread. 
     
    328330    * @note Currently, this is only available on IRIX 6.5 and Linux. 
    329331    */ 
    330    void setRunOn(const unsigned int cpu); 
     332   void setRunOn(const int cpu); 
    331333 
    332334   /** 
  • juggler/trunk/modules/vapor/vpr/md/WIN32/Thread/ThreadWin32.cpp

    r20817 r20822  
    306306} 
    307307 
    308 void ThreadWin32::setRunOn(const unsigned int cpu) 
     308void ThreadWin32::setRunOn(const int cpu) 
    309309{ 
    310310   // Even though we have easy access to mThreadHandle, we perform this test 
     
    312312   if ( ThreadWin32::self() == this ) 
    313313   { 
     314      if ( cpu < 0 ) 
     315      { 
     316         std::ostringstream msg_stream; 
     317         msg_stream << "Illegal CPU identifier " << cpu << " is less than 0"; 
     318         throw vpr::IllegalArgumentException(msg_stream.str(), VPR_LOCATION); 
     319      } 
     320 
    314321      // The value of cpu is zero-based, but the CPU identifier values from 
    315322      // Windows are one-based. 
  • juggler/trunk/modules/vapor/vpr/md/WIN32/Thread/ThreadWin32.h

    r20816 r20822  
    271271    * 
    272272    * @param cpu The CPU on which this thread will run exclusively. This value 
    273     *            is zero-based and therefore must be less than the number of 
    274     *            processors available on the computer. 
     273    *            is zero-based and therefore must be greater than 0 (zero) and 
     274    *            less than the number of processors available on the computer. 
    275275    * 
    276276    * @throw vpr::IllegalArgumentException 
    277277    *           Thrown if the thread spawned through the use of this object is 
    278278    *           not the thread from which this method was invoked. 
     279    * @throw vpr::IllegalArgumentException 
     280    *           Thrown if \p cpu is less than 0. 
    279281    * @throw vpr::Exception 
    280282    *           Thrown if the CPU affinity for the running thread could not 
    281283    *           be changed. 
     284    * 
     285    * @since 2.1.6 
    282286    */ 
    283287   void setRunOn(const unsigned int cpu); 
     
    302306    *           Thrown if the CPU affinity for the running thread could not 
    303307    *           be queried. 
     308    * 
     309    * @since 2.1.6 
    304310    */ 
    305311   std::vector<unsigned int> getRunOn() const;