Changeset 19650

Show
Ignore:
Timestamp:
12/13/06 10:46:23 (2 years ago)
Author:
patrick
Message:

Replaced fairly meaningless integer return codes in vpr::Thread with the use
of exceptions. I really hope that this is the last of the API changes needed
to move VPR over to using exceptions for error reporting.

Bumped version to 1.1.38.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vapor/ChangeLog

    r19627 r19650  
    11DATE       AUTHOR   CHANGE 
    22---------- -------- ----------------------------------------------------------- 
     32006-12-13 patrick  Replaced integer return codes in vpr::Thread with 
     4                    exceptions. 
     5                    NEW VERSION: 1.1.38 
    362006-12-11 patrick  Replaced integer return codes in vpr::ThreadKey with 
    47                    exceptions. 
  • juggler/trunk/modules/vapor/VERSION

    r19627 r19650  
     11.1.38-0 @12/13/2006 16:50:00 UTC@ 
    121.1.37-0 @12/11/2006 15:50:00 UTC@ 
    231.1.36-0 @12/08/2006 20:45:00 UTC@ 
  • juggler/trunk/modules/vapor/test/TestSuite/TestCases/Thread/ThreadTest.cpp

    r18810 r19650  
    174174   for(int t=0;t<num_threads;t++) 
    175175   { 
    176       if(threads[t]->join() == false) 
    177          CPPUNIT_ASSERT(false && "Thread was not able to be joined"); 
     176      threads[t]->join(); 
    178177      delete threads[t]; 
    179178   } 
     
    378377   for(int t=0;t<num_threads;t++) 
    379378   { 
    380       if(threads[t]->join() == false) 
    381          CPPUNIT_ASSERT(false && "Thread was not able to be joined"); 
     379      threads[t]->join(); 
    382380      delete threads[t]; 
    383381   } 
     
    415413   CPPUNIT_ASSERT(the_thread != NULL); 
    416414 
    417    CPPUNIT_ASSERT(the_thread->join() && "Failed to join with testThreadStackSize thread"); 
     415   the_thread->join(); 
    418416 
    419417   //CPPUNIT_ASSERT(mCounter == (num_threads*50000)); 
  • juggler/trunk/modules/vapor/vpr/Thread/BaseThread.h

    r19587 r19650  
    3939#include <vpr/vprConfig.h> 
    4040 
    41 #include <boost/concept_check.hpp> 
    4241#include <boost/function.hpp> 
    4342#include <vpr/vprTypes.h> 
     
    155154    * Causes the calling thread wait for the termination of this thread. 
    156155    * 
    157     * @post The caller blocks until this thread finishes its execution 
    158     *       (i.e., calls the exit() method).  This routine may return 
    159     *       immediately if this thread has already exited. 
     156    * @post The caller blocks until this thread finishes its execution. 
     157    *       This routine may return immediately if this thread has already 
     158    *       exited. 
    160159    * 
    161160    * @param status Current state of the terminating thread when that thread 
    162161    *               calls the exit routine (optional). 
    163162    * 
    164     * @return 0 is returned if this thread is "joined" successfully. 
    165     * @return -1 is returned on an error condition. 
    166     */ 
    167    virtual int join(void** status = 0) 
    168    { 
    169       boost::ignore_unused_variable_warning(status); 
    170       return -1; 
     163    * @note This implementation does onthing. See the derived classes for more 
     164    *       information. 
     165    */ 
     166   virtual void join(void** = NULL) 
     167   { 
     168      /* Do nothing. */ ; 
    171169   } 
    172170 
     
    175173    * using suspend()). 
    176174    * 
    177     * @return 0 is returned if this thread resumes execuation successfully. 
    178     * @return -1 is returned otherwise
    179     */ 
    180    virtual int resume() 
    181    { 
    182       return -1
     175    * @note This implementation does nothing. See the derived classes for more 
     176    *       information
     177    */ 
     178   virtual void resume() 
     179   { 
     180      /* Do nothing. */
    183181   } 
    184182 
     
    186184    * Suspends the execution of this thread. 
    187185    * 
    188     * @return 0 is returned if this thread is suspended successfully. 
    189     * @return -1 is returned otherwise. 
    190     */ 
    191    virtual int suspend() 
    192    { 
    193       return -1; 
    194    } 
    195  
    196    /** 
    197     * Gets this thread's current priority. 
    198     * 
    199     * @post The priority of this thread is returned in the integer pointer 
    200     *       variable. 
    201     * 
    202     * @param prio Pointer to an int variable that will have the thread's 
    203     *             priority stored in it. 
    204     * 
    205     * @return 0 is returned if the priority was retrieved successfully. 
    206     * @return -1 is returned if the priority could not be read. 
    207     */ 
    208    virtual int getPrio(VPRThreadPriority* prio) 
    209    { 
    210       boost::ignore_unused_variable_warning(prio); 
    211       return -1; 
     186    * @note This implementation does nothing. See the derived classes for more 
     187    *       information. 
     188    */ 
     189   virtual void suspend() 
     190   { 
     191      /* Do nothing. */ ; 
     192   } 
     193 
     194   /** 
     195    * Gets this thread's priority. 
     196    * 
     197    * @return This implementation always returns \c VPR_PRIORITY_NORMAL. See 
     198    *         the derived classes for more information. 
     199    */ 
     200   virtual VPRThreadPriority getPrio() 
     201   { 
     202      return VPR_PRIORITY_NORMAL; 
    212203   } 
    213204 
     
    217208    * @param prio The new priority for this thread. 
    218209    * 
    219     * @return 0 is returned if this thread's priority was set successfully. 
    220     * @return -1 is returned otherwise. 
    221     */ 
    222    virtual int setPrio(VPRThreadPriority prio) 
    223    { 
    224       boost::ignore_unused_variable_warning(prio); 
    225       return -1; 
     210    * @note This implementation does nothing. See the derived classes for more 
     211    *       information. 
     212    */ 
     213   virtual void setPrio(const VPRThreadPriority) 
     214   { 
     215      /* Do nothing. */ ; 
    226216   } 
    227217 
     
    260250    * @post This thread receives the specified signal. 
    261251    * 
    262     * @param signum The signal to send to the specified thread. 
    263     * 
    264     * @return 0 is returned if the thread was sent the given signal. 
    265     * @return -1 is returned if an error occurred. 
    266     */ 
    267    virtual int kill(int signum) 
    268    { 
    269       boost::ignore_unused_variable_warning(signum); 
    270       return -1; 
     252    * @param signum The signal to send to this thread. 
     253    * 
     254    * @note This implementation does nothing. See the derived classes for 
     255    *       more information. 
     256    */ 
     257   virtual void kill(const int) 
     258   { 
     259      /* Do nothing. */ ; 
    271260   } 
    272261 
     
    275264    * 
    276265    * @post This thread is cancelled. Immediate cancellation is not guaranteed. 
     266    * 
     267    * @note This implementation does nothing. See the derived classes for 
     268    *       more information. 
    277269    */ 
    278270   virtual void kill() 
    279    {;} 
     271   { 
     272      /* Do nothing. */ ; 
     273   } 
    280274 
    281275   /** 
  • juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.cpp

    r19349 r19650  
    3939#include <sstream> 
    4040#include <typeinfo> 
    41 #include <boost/concept_check.hpp> 
    4241#include <boost/bind.hpp> 
    4342 
     
    174173} 
    175174 
    176 int ThreadNSPR::join(void** status) 
    177 
    178    boost::ignore_unused_variable_warning(status); 
    179    int return_status = PR_JoinThread(mThread); 
    180  
    181    if (mCaughtException) 
     175int ThreadNSPR::join(void**) 
     176
     177   const PRStatus result = PR_JoinThread(mThread); 
     178 
     179   if ( PR_FAILURE == result ) 
     180   { 
     181      throw vpr::IllegalArgumentException("Failed to join invalid thread", 
     182                                          VPR_LOCATION); 
     183   } 
     184 
     185   if ( mCaughtException ) 
    182186   { 
    183187      throw mException; 
    184188   } 
    185  
    186    return return_status; 
    187189} 
    188190 
     
    263265} 
    264266 
     267BaseThread::VPRThreadPriority ThreadNSPR::getPrio() 
     268{ 
     269   return nsprThreadPriorityToVPR(PR_GetThreadPriority(mThread)); 
     270} 
    265271 
    266272// Set this thread's priority. 
    267 int ThreadNSPR::setPrio(VPRThreadPriority prio) 
    268 
    269    int retval(0); 
    270  
    271    if ( prio > 3 ) 
    272    { 
    273       retval = -1; 
    274    } 
    275    else 
    276    { 
    277       PR_SetThreadPriority(mThread, vprThreadPriorityToNSPR(prio)); 
    278    } 
    279  
    280    return retval; 
     273void ThreadNSPR::setPrio(const VPRThreadPriority prio) 
     274
     275   PR_SetThreadPriority(mThread, vprThreadPriorityToNSPR(prio)); 
    281276} 
    282277 
  • juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.h

    r19333 r19650  
    5050#include <prthread.h> 
    5151#include <prtypes.h> 
    52 #include <boost/concept_check.hpp> 
    5352 
    5453#include <vpr/Thread/BaseThread.h> 
     
    173172    * Makes the calling thread wait for the termination of this thread. 
    174173    * 
    175     * @pre None. 
    176     * @post The caller blocks until this thread finishes its execution 
    177     *        (i.e., finishes its root function).  This routine may return 
    178     *        immediately if this thread has already exited. 
    179     * 
    180     * @return 0 is returned upon successful completion.  -1 is returned if 
    181     *         an error occurred. 
    182     * @throw vpr::UncaughtThreadException. 
    183     */ 
    184    virtual int join(void** status = NULL); 
     174    * @post The caller blocks until this thread finishes its execution. This 
     175    *       routine may return immediately if this thread has already exited. 
     176    * 
     177    * @param status Current state of the terminating thread when that 
     178    *               thread calls the exit routine (optional). This parameter 
     179    *               is not used by this implementation. 
     180    * 
     181    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     182    *        thread or not a joinable thread. In either case, this thread 
     183    *        cannot be joined. 
     184    * @throw vpr::UncaughtThreadException is thrown if an exception was 
     185    *        thrown by code executing in this thread and was not caught. 
     186    */ 
     187   virtual void join(void** status = NULL); 
    185188 
    186189   /** 
     
    190193    * @pre This thread was previously suspended using the suspend() member 
    191194    *       function. 
    192     * @post This thread is sent the SIGCONT signal and is allowed to begin 
     195    * @post This thread is sent the \c SIGCONT signal and is allowed to begin 
    193196    *        executing again. 
    194197    * 
    195     * @return 0 is returned upon successful completion.  -1 is returned if 
    196     *         an error occurred. 
    197     */ 
    198    virtual int resume() 
    199    { 
    200 //      return kill(SIGCONT); 
    201       return -1; 
     198    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     199    *        thread and thus cannot receive a signal. 
     200    * 
     201    * @note This operation is not currently supported with NSPR threads. 
     202    */ 
     203   virtual void resume() 
     204   { 
     205//      this->kill(SIGCONT); 
    202206   } 
    203207 
     
    205209    * Suspends the execution of this thread. 
    206210    * 
    207     * @post This thread is sent the SIGSTOP signal and is thus suspended 
    208     *        from execution until the member function resume() is called. 
    209     * 
    210     * @return 0 is returned upon successful completion.  -1 is returned if 
    211     *         an error occurred. 
    212     */ 
    213    virtual int suspend() 
    214    { 
    215 //      return kill(SIGSTOP); 
    216       return -1; 
     211    * @pre This is a valid thread. 
     212    * @post This thread is sent the \c SIGSTOP signal and is thus suspended 
     213    *       from execution until the member function resume() is called. 
     214    * 
     215    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     216    *        thread and thus cannot receive a signal. 
     217    * 
     218    * @note This operation is not currently supported with NSPR threads. 
     219    */ 
     220   virtual void suspend() 
     221   { 
     222//      this->kill(SIGSTOP); 
    217223   } 
    218224 
     
    221227    * 
    222228    * @pre This is a valid thread. 
    223     * @post The priority of this thread is returned in the integer pointer 
    224     *        variable. 
    225     * 
    226     * @param prio Pointer to an int variable that will have the thread's 
    227     *             priority stored in it. 
    228     * 
    229     * @return 0 is returned upon successful completion.  -1 is returned if 
    230     *         an error occurred. 
    231     */ 
    232    virtual int getPrio(VPRThreadPriority* prio) 
    233    { 
    234       *prio = nsprThreadPriorityToVPR(PR_GetThreadPriority(mThread)); 
    235  
    236       return 0; 
    237    } 
     229    * 
     230    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     231    *        thread (and thus cannot have its scheduling queried). 
     232    */ 
     233   virtual VPRThreadPriority getPrio(); 
    238234 
    239235   /** 
     
    242238    * @post This thread has its priority set to the specified value. 
    243239    * 
    244     * @param prio  The new priority for this thread. 
    245     * 
    246     * @return 0 is returned upon successful completion.  -1 is returned if 
    247     *         an error occurred. 
     240    * @param prio The new priority for this thread. 
    248241    * 
    249242    * @note The priority must correspond to a value in the PRThreadPriority 
    250243    *        enumerated type. 
    251244    */ 
    252    virtual int setPrio(VPRThreadPriority prio); 
    253  
    254    /** 
    255     * Sends the specified signal to this thread (not necessarily SIGKILL). 
     245   virtual void setPrio(const VPRThreadPriority prio); 
     246 
     247   /** 
     248    * Sends the specified signal to this thread (not necessarily \c SIGKILL). 
    256249    * 
    257250    * @post This thread receives the specified signal. 
    258251    * 
    259     * @param signum  The signal to send to the specified thread. 
    260     * 
    261     * @return 0 is returned upon successful completion.  -1 is returned if 
    262     *         an error occurred. 
    263     */ 
    264    virtual int kill(int signum) 
    265    { 
    266       boost::ignore_unused_variable_warning(signum); 
    267       return -1; 
     252    * @param signum The signal to send to the specified thread. 
     253    * 
     254    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     255    *        thread and thus cannot receive a signal or if the given signal 
     256    *        number is invalid. 
     257    * 
     258    * @note This operation is not currently supported by NSPR threads. 
     259    */ 
     260   virtual void kill(const int) 
     261   { 
     262      /* Do nothing. */ ; 
    268263   } 
    269264 
     
    277272    *        cancellation is not guaranteed. 
    278273    * 
    279     * @note For the sake of clarity, it is probably better to use the 
    280     *        cancel() routine instead of kill() because a two-argument 
    281     *        version of kill() is also used for sending signals to threads. 
    282     *        This kill() and cancel() do exactly the same thing. 
     274    * @note This operation is not currently supported by NSPR threads. 
    283275    */ 
    284276   virtual void kill() 
    285277   { 
     278      /* Do nothing. */ ; 
    286279   } 
    287280 
  • juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.cpp

    r19333 r19650  
    6060#include <vpr/Util/IllegalArgumentException.h> 
    6161#include <vpr/Util/ResourceException.h> 
     62#include <vpr/Sync/DeadlockException.h> 
    6263#include <vpr/md/POSIX/Thread/ThreadPosix.h> 
    6364 
     
    293294} 
    294295 
     296void ThreadPosix::join(void** status) 
     297{ 
     298   const int result = pthread_join(mThread, status); 
     299 
     300   if ( EINVAL == result ) 
     301   { 
     302      throw vpr::IllegalArgumentException("Cannot join an unjoinable thread", 
     303                                          VPR_LOCATION); 
     304   } 
     305   else if ( ESRCH == result ) 
     306   { 
     307      throw vpr::IllegalArgumentException("Cannot join an invalid thread", 
     308                                          VPR_LOCATION); 
     309   } 
     310   else if ( EDEADLK == result ) 
     311   { 
     312      throw vpr::DeadlockException("Deadlock detected when joining thread", 
     313                                   VPR_LOCATION); 
     314   } 
     315 
     316   vprASSERT(result == 0); 
     317 
     318   if ( mCaughtException ) 
     319   { 
     320      throw mException; 
     321   } 
     322} 
     323 
    295324// Get this thread's priority. 
    296 int ThreadPosix::getPrio(VPRThreadPriority* prio
     325BaseThread::VPRThreadPriority ThreadPosix::getPrio(
    297326{ 
    298327#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING 
    299    int policy, ret_val
     328   int policy
    300329   sched_param_t fifo_sched_param; 
    301330 
    302    ret_val = pthread_getschedparam(mThread, &policy, &fifo_sched_param); 
    303    *prio = posixThreadPriorityToVPR(fifo_sched_param.sched_priority); 
    304  
    305    return ret_val; 
     331   const int result = pthread_getschedparam(mThread, &policy, 
     332                                            &fifo_sched_param); 
     333 
     334   if ( ESRCH == result ) 
     335   { 
     336      throw vpr::IllegalArgumentException( 
     337         "Cannot query priority for invalid thread", VPR_LOCATION 
     338      ); 
     339   } 
     340 
     341   vprASSERT(result == 0); 
     342 
     343   return posixThreadPriorityToVPR(fifo_sched_param.sched_priority); 
    306344#else 
    307345   std::cerr << "vpr::ThreadPosix::getPrio(): Not supported\n"; 
    308346 
    309    return -1
     347   return VPR_PRIORITY_NORMAL
    310348#endif 
    311349} 
    312350 
    313351// Set this thread's priority. 
    314 int ThreadPosix::setPrio(VPRThreadPriority prio) 
     352void ThreadPosix::setPrio(VPRThreadPriority prio) 
    315353{ 
    316354#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING 
    317355   sched_param_t sched_param; 
    318    sched_param.sched_priority = prio; 
    319  
    320    return pthread_setschedparam(mThread, SCHED_RR, &sched_param); 
     356   sched_param.sched_priority = vprThreadPriorityToPOSIX(prio); 
     357 
     358   const int result = pthread_setschedparam(mThread, SCHED_RR, &sched_param); 
     359 
     360   if ( EINVAL == result || ENOTSUP == result ) 
     361   { 
     362      std::ostringstream msg_stream; 
     363      msg_stream << "Invalid priority value " << sched_param.sched_priority; 
     364      throw vpr::IllegalArgumentException(msg_stream.str(), VPR_LOCATION); 
     365   } 
     366   else if ( ESRCH == result ) 
     367   { 
     368      throw vpr::IllegalArgumentException( 
     369         "Cannot set priority for invalid thread", VPR_LOCATION 
     370      ); 
     371   } 
     372 
     373   vprASSERT(result == 0); 
    321374#else 
    322375   boost::ignore_unused_variable_warning(prio); 
    323376   std::cerr << "vpr::ThreadPosix::setPrio(): Not supported\n"; 
    324  
    325    return -1; 
    326377#endif 
    327378} 
    328379 
    329 int ThreadPosix::setRunOn(int cpu) 
     380void ThreadPosix::setRunOn(const int cpu) 
    330381{ 
    331382#ifdef VPR_OS_IRIX 
    332    int ret_val; 
    333  
    334    if ( mScope == PTHREAD_SCOPE_SYSTEM ) 
    335    { 
    336       ret_val = pthread_setrunon_np(cpu); 
     383   if ( mScope == VPR_GLOBAL_THREAD ) 
     384   { 
     385      pthread_setrunon_np(cpu); 
    337386   } 
    338387   else 
    339388   { 
    340       std::cerr << "This thread is not a system-scope thread!\n"; 
    341       ret_val = -1; 
    342    } 
    343  
    344    return ret_val; 
     389      throw vpr::IllegalArgumentException( 
     390         "This thread is not a system-scope thread", VPR_LOCATION 
     391      ); 
     392   } 
    345393#else 
    346394   boost::ignore_unused_variable_warning(cpu); 
    347395   std::cerr << "vpr::ThreadPosix::setRunOn(): Not available on this system.\n"; 
    348  
    349    return -1; 
    350396#endif 
    351397} 
    352398 
    353 int ThreadPosix::getRunOn(int* cur_cpu
     399int ThreadPosix::getRunOn(
    354400{ 
    355401#ifdef VPR_OS_IRIX 
    356    int ret_val
    357  
    358    if ( mScope == PTHREAD_SCOPE_SYSTEM
    359    { 
    360       ret_val = pthread_getrunon_np(cur_cpu); 
     402   int cur_cpu
     403 
     404   if ( mScope == VPR_GLOBAL_THREAD
     405   { 
     406      pthread_getrunon_np(&cur_cpu); 
    361407   } 
    362408   else 
    363409   { 
    364       std::cerr << "This thread is not a system-scope thread!\n"; 
    365       ret_val = -1; 
    366    } 
    367  
    368    return ret_val; 
     410      throw vpr::IllegalArgumentException( 
     411         "This thread is not a system-scope thread", VPR_LOCATION 
     412      ); 
     413   } 
     414 
     415   return cur_cpu; 
    369416#else 
    370    boost::ignore_unused_variable_warning(cur_cpu); 
    371417   std::cerr << "vpr::ThreadPosix::getRunOn(): Not available on this system.\n"; 
    372  
    373    return -1; 
     418   return 0; 
    374419#endif 
    375420} 
    376421 
    377 int ThreadPosix::kill(int signum) 
    378 
    379    return pthread_kill(mThread, signum); 
     422void ThreadPosix::kill(const int signum) 
     423
     424   const int result = pthread_kill(mThread, signum); 
     425 
     426   if ( ESRCH == result ) 
     427   { 
     428      throw vpr::IllegalArgumentException("Cannot kill an invalid thread", 
     429                                          VPR_LOCATION); 
     430   } 
     431   else if ( EINVAL == result ) 
     432   { 
     433      std::ostringstream msg_stream; 
     434      msg_stream << "Invalid signal number " << signum; 
     435      throw vpr::IllegalArgumentException(msg_stream.str(), VPR_LOCATION); 
     436   } 
     437 
     438   vprASSERT(result == 0); 
    380439} 
    381440 
     
    473532} 
    474533 
    475 BaseThread::VPRThreadPriority ThreadPosix::posixThreadPriorityToVPR(const int priority) 
     534BaseThread::VPRThreadPriority ThreadPosix:: 
     535posixThreadPriorityToVPR(const int priority) 
    476536{ 
    477537   VPRThreadPriority vpr_prio; 
  • juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.h

    r19584 r19650  
    218218    * Makes the calling thread wait for the termination of this thread. 
    219219    * 
    220     * @post The caller blocks until this thread finishes its execution 
    221     *       (i.e., calls the exit() method).  This routine may return 
    222     *       immediately if this thread has already exited. 
     220    * @post The caller blocks until this thread finishes its execution. This 
     221    *       routine may return immediately if this thread has already exited. 
    223222    * 
    224223    * @param status Current state of the terminating thread when that 
    225224    *               thread calls the exit routine (optional). 
    226225    * 
    227     * @return 0 is returned if this thread is "joined" successfully.<br> 
    228     *         -1 is returned on an error condition. 
    229     * 
     226    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     227    *        thread or not a joinable thread. In either case, this thread 
     228    *        cannot be joined. 
     229    * @throw vpr::DeadlockException is thrown if deadlock is detected when 
     230    *        trying to join this thread. 
    230231    * @throw vpr::UncaughtThreadException is thrown if an exception was 
    231232    *        thrown by code executing in this thread and was not caught. 
    232233    */ 
    233    virtual int join(void** status = 0) 
    234    { 
    235       int return_status = pthread_join(mThread, status); 
    236  
    237       if (mCaughtException) 
    238       { 
    239          throw mException; 
    240       } 
    241  
    242       return return_status; 
    243    } 
     234   virtual void join(void** status = NULL); 
    244235 
    245236   /** 
     
    249240    * @pre This thread was previously suspended using the suspend() member 
    250241    *      function. 
    251     * @post This thread is sent the SIGCONT signal and is allowed to begin 
     242    * @post This thread is sent the \c SIGCONT signal and is allowed to begin 
    252243    *       executing again. 
    253244    * 
    254     * @return 0 is returned if this thread resumes execuation successfully. 
    255     *        -1 is returned otherwise
     245    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     246    *        thread and thus cannot receive a signal
    256247    * 
    257248    * @note This is not currently supported on HP-UX 10.20. 
    258249    */ 
    259    virtual int resume() 
    260    { 
    261       return kill(SIGCONT); 
     250   virtual void resume() 
     251   { 
     252      this->kill(SIGCONT); 
    262253   } 
    263254 
     
    265256    * Suspends the execution of this thread. 
    266257    * 
    267     * @post This thread is sent the SIGSTOP signal and is thus suspended 
     258    * @pre This is a valid thread. 
     259    * @post This thread is sent the \c SIGSTOP signal and is thus suspended 
    268260    *       from execution until the member function resume() is called. 
    269261    * 
    270     * @return 0 is returned if this thread is suspended successfully. 
    271     *        -1 is returned otherwise
     262    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     263    *        thread and thus cannot receive a signal
    272264    * 
    273265    * @note This is not currently supported on HP-UX 10.20. 
    274266    */ 
    275    virtual int suspend() 
    276    { 
    277       return kill(SIGSTOP); 
     267   virtual void suspend() 
     268   { 
     269      this->kill(SIGSTOP); 
    278270   } 
    279271 
     
    281273    * Gets this thread's priority. 
    282274    * 
    283     * @post The priority of this thread is returned in the integer pointer 
    284     *       variable. 
    285     * 
    286     * @param prio Pointer to an int variable that will have the thread's 
    287     *             priority stored in it
    288     * 
    289     * @return 0 is returned if the priority was retrieved successfully. 
    290     *        -1 is returned if the priority could not be read
     275    * @pre This is a valid thread. 
     276    * 
     277    * @return The VPRThreadPriority value indicating the priority of this 
     278    *         thread is returned. If the priority cannot be queried, then 
     279    *         \c VPR_PRIORITY_NORMAL is returned
     280    * 
     281    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     282    *        thread (and thus cannot have its scheduling queried)
    291283    * 
    292284    * @note This is only supported on systems that support thread priority 
    293285    *       scheduling in their pthreads implementation. 
    294286    */ 
    295    virtual int getPrio(VPRThreadPriority* prio); 
     287   virtual VPRThreadPriority getPrio(); 
    296288 
    297289   /** 
     
    302294    * @param prio The new priority for this thread. 
    303295    * 
    304     * @return 0 is returned if this thread's priority was set successfully. 
    305     *         -1 is returned otherwise. 
     296    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     297    *        thread (and thus cannot have its scheduling changed) or if the 
     298    *        given priority is invalid. 
    306299    * 
    307300    * @note This is only supported on systems that support thread priority 
    308301    *       scheduling in their pthreads implementation. 
    309302    */ 
    310    virtual int setPrio(VPRThreadPriority prio); 
     303   virtual void setPrio(const VPRThreadPriority prio); 
    311304 
    312305   /** 
     
    319312    * @param cpu The CPU on which this thread will run exclusively. 
    320313    * 
    321     * @return 0 is returned if the affinity is set successfully. 
    322     *        -1 is returned otherwise
     314    * @throw vpr::IllegalArgumentException is thrown if this is not a 
     315    *        system-scope (i.e., global) thread
    323316    * 
    324317    * @note This is currently only available on IRIX 6.5 and is non-portable. 
    325318    */ 
    326    virtual int setRunOn(int cpu); 
     319   virtual void setRunOn(const int cpu); 
    327320 
    328321   /** 
     
    335328    *       pointer. 
    336329    * 
    337     * @param cur_cpu The CPU affinity for this thread (set by a previous 
    338     *                call to setRunOn(). 
    339     * 
    340     * @return 0 is returned if the affinity is retrieved successfully. 
    341     *        -1 is returned otherwise
     330    * @return The CPU affinity for this thread (set by a previous call to 
     331    *         setRunOn()); 
     332    * 
     333    * @throw vpr::IllegalArgumentException is thrown if this is not a 
     334    *        system-scope (i.e., global) thread
    342335    * 
    343336    * @note This is currently only available on IRIX 6.5 and is non-portable. 
    344337    */ 
    345    virtual int getRunOn(int* cur_cpu); 
     338   virtual int getRunOn(); 
    346339 
    347340   /** 
     
    358351 
    359352   /** 
    360     * Sends the specified signal to this thread (not necessarily SIGKILL). 
    361     * 
     353    * Sends the specified signal to this thread (not necessarily \c SIGKILL). 
     354    * 
     355    * @pre This is a valid thread. 
    362356    * @post This thread receives the specified signal. 
    363357    * 
    364     * @param signum The signal to send to the specified thread. 
    365     * 
    366     * @return 0 is returned if the signal was sent successfully. 
    367     *         -1 is returned otherwise. 
     358    * @param signum The signal to send to this thread. 
     359    * 
     360    * @throw vpr::IllegalArgumentException is thrown if this is not a valid 
     361    *        thread and thus cannot receive a signal or if the given signal 
     362    *        number is invalid. 
    368363    * 
    369364    * @note This is not currently supported with Pthreads Draft 4. 
    370365    */ 
    371    virtual int kill(int signum); 
     366   virtual void kill(const int signum); 
    372367 
    373368   /** 
     
    379374    *       stop or it may ignore the cancel altogether.  Thus, immediate 
    380375    *       cancellation is not guaranteed. 
    381     * 
    382     * @note For the sake of clarity, it is probably better to use the 
    383     *       cancel() routine instead of kill() because a two-argument 
    384     *       version of kill() is also used for sending signals to threads. 
    385     *       This kill() and cancel() do exactly the same thing. 
    386376    */ 
    387377   virtual void kill() 
  • juggler/trunk/modules/vapor/vpr/md/SPROC/Thread/ThreadSGI.cpp

    r19333 r19650  
    204204 * thread. 
    205205 */ 
    206 int ThreadSGI::join(void** arg) 
    207 
    208    int status, retval; 
     206void ThreadSGI::join(void** status) 
     207
    209208   pid_t pid; 
    210209 
    211210   do 
    212211   { 
    213       pid = ::waitpid(mThreadPID, &status, 0); 
    214    } while ( WIFSTOPPED(status) != 0 ); 
     212      pid = ::waitpid(mThreadPID, &exit_status, 0); 
     213   } while ( WIFSTOPPED(exit_status) != 0 ); 
    215214 
    216215   if ( pid > -1 ) 
     
    218217      vprASSERT(pid == mThreadPID); 
    219218 
    220       if ( WIFEXITED(status) != 0 && arg != NULL ) 
    221       { 
    222          **((int**) arg) = WEXITSTATUS(status); 
    223       } 
    224       else if ( WIFSIGNALED(status) != 0 && arg != NULL ) 
    225       { 
    226          **((int**) arg) = WTERMSIG(status); 
    227       } 
    228  
    229       retval = 0; 
     219      if ( WIFEXITED(exit_status) != 0 && arg != NULL ) 
     220      { 
     221         **((int**) arg) = WEXITSTATUS(exit_status); 
     222      } 
     223      else if ( WIFSIGNALED(exit_status) != 0 && arg != NULL ) 
     224      { 
     225         **((int**) arg) = WTERMSIG(exit_status); 
     226      } 
    230227   } 
    231228   else 
    232229   { 
    233       retval = -1; 
    234    } 
    235  
    236    if (mCaughtException) 
     230      throw vpr::IllegalArgumentException("Cannot join an invalid thread", 
     231                                          VPR_LOCATION); 
     232   } 
     233 
     234   if ( mCaughtException ) 
    237235   { 
    238236      throw mException; 
    239237   } 
    240  
    241    return retval; 
     238
     239 
     240BaseThread::VPRThreadPriority ThreadSGI::getPrio() 
     241
     242   int prio = getpriority(PRIO_PROCESS, mThreadPID); 
     243 
     244   if ( prio == -1 ) 
     245   { 
     246      switch ( errno ) 
     247      { 
     248         case ESRCH: 
     249            throw vpr::IllegalArgumentException( 
     250               "Cannot query priority for invalid thread", VPR_LOCATION 
     251            ); 
     252            break; 
     253      } 
     254   } 
     255 
     256   return unixThreadPriorityToVPR(prio); 
     257
     258 
     259void ThreadSGI::setPrio(const VPRThreadPriority prio) 
     260
     261   const int result = setpriority(PRIO_PROCESS, mThreadPID, 
     262                                  vprThreadPriorityToUNIX(prio)); 
     263 
     264   if ( result == -1 ) 
     265   { 
     266      switch ( errno ) 
     267      { 
     268         case ESRCH: 
     269            throw vpr::IllegalArgumentException( 
     270               "Cannot set priority for invalid thread", VPR_LOCATION 
     271            ); 
     272            break; 
     273         case EPERM: 
     274            { 
     275               std::ostringstream msg_stream; 
     276               msg_stream << "Permission denied when setting thread priority: " 
     277                          << strerror(errno); 
     278               throw vpr::Exception(msg_stream.str(), VPR_LOCATION); 
     279            } 
     280            break; 
     281         case EACCESS: 
     282            { 
     283               std::ostringstream msg_stream; 
     284               msg_stream << "Only super-user can lower a process priority: " 
     285                          << strerror(errno); 
     286               throw vpr::Exception(msg_stream.str(), VPR_LOCATION); 
     287            } 
     288            break; 
     289      } 
     290   } 
     291 
     292   vprASSERT(result == 0); 
     293
     294 
     295void ThreadSGI::kill(const int signum) 
     296
     297   const int result = ::kill(mThreadPID, signum); 
     298 
     299   if ( result == -1 ) 
     300   { 
     301      switch ( errno ) 
     302      { 
     303         case EINVAL: 
     304            { 
     305               std::ostringstream msg_stream; 
     306               msg_stream << "Invalid signal number " << signum; 
     307               throw vpr::IllegalArgumentException(msg_stream.str(), 
     308                                                   VPR_LOCATION); 
     309            } 
     310