Changeset 19650
- Timestamp:
- 12/13/06 10:46:23 (2 years ago)
- Files:
-
- juggler/trunk/modules/vapor/ChangeLog (modified) (1 diff)
- juggler/trunk/modules/vapor/VERSION (modified) (1 diff)
- juggler/trunk/modules/vapor/test/TestSuite/TestCases/Thread/ThreadTest.cpp (modified) (3 diffs)
- juggler/trunk/modules/vapor/vpr/Thread/BaseThread.h (modified) (7 diffs)
- juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.cpp (modified) (3 diffs)
- juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.h (modified) (7 diffs)
- juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.cpp (modified) (3 diffs)
- juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.h (modified) (9 diffs)
- juggler/trunk/modules/vapor/vpr/md/SPROC/Thread/ThreadSGI.cpp (modified) (3 diffs)
- juggler/trunk/modules/vapor/vpr/md/SPROC/Thread/ThreadSGI.h (modified) (7 diffs)
- juggler/trunk/modules/vapor/vpr/md/WIN32/Thread/ThreadWin32.cpp (modified) (2 diffs)
- juggler/trunk/modules/vapor/vpr/md/WIN32/Thread/ThreadWin32.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
juggler/trunk/modules/vapor/ChangeLog
r19627 r19650 1 1 DATE AUTHOR CHANGE 2 2 ---------- -------- ----------------------------------------------------------- 3 2006-12-13 patrick Replaced integer return codes in vpr::Thread with 4 exceptions. 5 NEW VERSION: 1.1.38 3 6 2006-12-11 patrick Replaced integer return codes in vpr::ThreadKey with 4 7 exceptions. juggler/trunk/modules/vapor/VERSION
r19627 r19650 1 1.1.38-0 @12/13/2006 16:50:00 UTC@ 1 2 1.1.37-0 @12/11/2006 15:50:00 UTC@ 2 3 1.1.36-0 @12/08/2006 20:45:00 UTC@ juggler/trunk/modules/vapor/test/TestSuite/TestCases/Thread/ThreadTest.cpp
r18810 r19650 174 174 for(int t=0;t<num_threads;t++) 175 175 { 176 if(threads[t]->join() == false) 177 CPPUNIT_ASSERT(false && "Thread was not able to be joined"); 176 threads[t]->join(); 178 177 delete threads[t]; 179 178 } … … 378 377 for(int t=0;t<num_threads;t++) 379 378 { 380 if(threads[t]->join() == false) 381 CPPUNIT_ASSERT(false && "Thread was not able to be joined"); 379 threads[t]->join(); 382 380 delete threads[t]; 383 381 } … … 415 413 CPPUNIT_ASSERT(the_thread != NULL); 416 414 417 CPPUNIT_ASSERT(the_thread->join() && "Failed to join with testThreadStackSize thread");415 the_thread->join(); 418 416 419 417 //CPPUNIT_ASSERT(mCounter == (num_threads*50000)); juggler/trunk/modules/vapor/vpr/Thread/BaseThread.h
r19587 r19650 39 39 #include <vpr/vprConfig.h> 40 40 41 #include <boost/concept_check.hpp>42 41 #include <boost/function.hpp> 43 42 #include <vpr/vprTypes.h> … … 155 154 * Causes the calling thread wait for the termination of this thread. 156 155 * 157 * @post The caller blocks until this thread finishes its execution 158 * (i.e., calls the exit() method). This routine may return159 * immediately if this thread has alreadyexited.156 * @post The caller blocks until this thread finishes its execution. 157 * This routine may return immediately if this thread has already 158 * exited. 160 159 * 161 160 * @param status Current state of the terminating thread when that thread 162 161 * calls the exit routine (optional). 163 162 * 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. */ ; 171 169 } 172 170 … … 175 173 * using suspend()). 176 174 * 177 * @ return 0 is returned if this thread resumes execuation successfully.178 * @return -1 is returned otherwise.179 */ 180 virtual intresume()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. */ ; 183 181 } 184 182 … … 186 184 * Suspends the execution of this thread. 187 185 * 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; 212 203 } 213 204 … … 217 208 * @param prio The new priority for this thread. 218 209 * 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. */ ; 226 216 } 227 217 … … 260 250 * @post This thread receives the specified signal. 261 251 * 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. */ ; 271 260 } 272 261 … … 275 264 * 276 265 * @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. 277 269 */ 278 270 virtual void kill() 279 {;} 271 { 272 /* Do nothing. */ ; 273 } 280 274 281 275 /** juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.cpp
r19349 r19650 39 39 #include <sstream> 40 40 #include <typeinfo> 41 #include <boost/concept_check.hpp>42 41 #include <boost/bind.hpp> 43 42 … … 174 173 } 175 174 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) 175 int 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 ) 182 186 { 183 187 throw mException; 184 188 } 185 186 return return_status;187 189 } 188 190 … … 263 265 } 264 266 267 BaseThread::VPRThreadPriority ThreadNSPR::getPrio() 268 { 269 return nsprThreadPriorityToVPR(PR_GetThreadPriority(mThread)); 270 } 265 271 266 272 // 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; 273 void ThreadNSPR::setPrio(const VPRThreadPriority prio) 274 { 275 PR_SetThreadPriority(mThread, vprThreadPriorityToNSPR(prio)); 281 276 } 282 277 juggler/trunk/modules/vapor/vpr/md/NSPR/Thread/ThreadNSPR.h
r19333 r19650 50 50 #include <prthread.h> 51 51 #include <prtypes.h> 52 #include <boost/concept_check.hpp>53 52 54 53 #include <vpr/Thread/BaseThread.h> … … 173 172 * Makes the calling thread wait for the termination of this thread. 174 173 * 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); 185 188 186 189 /** … … 190 193 * @pre This thread was previously suspended using the suspend() member 191 194 * function. 192 * @post This thread is sent the SIGCONT signal and is allowed to begin195 * @post This thread is sent the \c SIGCONT signal and is allowed to begin 193 196 * executing again. 194 197 * 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); 202 206 } 203 207 … … 205 209 * Suspends the execution of this thread. 206 210 * 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); 217 223 } 218 224 … … 221 227 * 222 228 * @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(); 238 234 239 235 /** … … 242 238 * @post This thread has its priority set to the specified value. 243 239 * 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. 248 241 * 249 242 * @note The priority must correspond to a value in the PRThreadPriority 250 243 * enumerated type. 251 244 */ 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). 256 249 * 257 250 * @post This thread receives the specified signal. 258 251 * 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. */ ; 268 263 } 269 264 … … 277 272 * cancellation is not guaranteed. 278 273 * 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. 283 275 */ 284 276 virtual void kill() 285 277 { 278 /* Do nothing. */ ; 286 279 } 287 280 juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.cpp
r19333 r19650 60 60 #include <vpr/Util/IllegalArgumentException.h> 61 61 #include <vpr/Util/ResourceException.h> 62 #include <vpr/Sync/DeadlockException.h> 62 63 #include <vpr/md/POSIX/Thread/ThreadPosix.h> 63 64 … … 293 294 } 294 295 296 void 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 295 324 // Get this thread's priority. 296 int ThreadPosix::getPrio(VPRThreadPriority* prio)325 BaseThread::VPRThreadPriority ThreadPosix::getPrio() 297 326 { 298 327 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING 299 int policy , ret_val;328 int policy; 300 329 sched_param_t fifo_sched_param; 301 330 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); 306 344 #else 307 345 std::cerr << "vpr::ThreadPosix::getPrio(): Not supported\n"; 308 346 309 return -1;347 return VPR_PRIORITY_NORMAL; 310 348 #endif 311 349 } 312 350 313 351 // Set this thread's priority. 314 intThreadPosix::setPrio(VPRThreadPriority prio)352 void ThreadPosix::setPrio(VPRThreadPriority prio) 315 353 { 316 354 #ifdef _POSIX_THREAD_PRIORITY_SCHEDULING 317 355 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); 321 374 #else 322 375 boost::ignore_unused_variable_warning(prio); 323 376 std::cerr << "vpr::ThreadPosix::setPrio(): Not supported\n"; 324 325 return -1;326 377 #endif 327 378 } 328 379 329 int ThreadPosix::setRunOn(int cpu)380 void ThreadPosix::setRunOn(const int cpu) 330 381 { 331 382 #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); 337 386 } 338 387 else 339 388 { 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 } 345 393 #else 346 394 boost::ignore_unused_variable_warning(cpu); 347 395 std::cerr << "vpr::ThreadPosix::setRunOn(): Not available on this system.\n"; 348 349 return -1;350 396 #endif 351 397 } 352 398 353 int ThreadPosix::getRunOn( int* cur_cpu)399 int ThreadPosix::getRunOn() 354 400 { 355 401 #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); 361 407 } 362 408 else 363 409 { 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; 369 416 #else 370 boost::ignore_unused_variable_warning(cur_cpu);371 417 std::cerr << "vpr::ThreadPosix::getRunOn(): Not available on this system.\n"; 372 373 return -1; 418 return 0; 374 419 #endif 375 420 } 376 421 377 int ThreadPosix::kill(int signum) 378 { 379 return pthread_kill(mThread, signum); 422 void 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); 380 439 } 381 440 … … 473 532 } 474 533 475 BaseThread::VPRThreadPriority ThreadPosix::posixThreadPriorityToVPR(const int priority) 534 BaseThread::VPRThreadPriority ThreadPosix:: 535 posixThreadPriorityToVPR(const int priority) 476 536 { 477 537 VPRThreadPriority vpr_prio; juggler/trunk/modules/vapor/vpr/md/POSIX/Thread/ThreadPosix.h
r19584 r19650 218 218 * Makes the calling thread wait for the termination of this thread. 219 219 * 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. 223 222 * 224 223 * @param status Current state of the terminating thread when that 225 224 * thread calls the exit routine (optional). 226 225 * 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. 230 231 * @throw vpr::UncaughtThreadException is thrown if an exception was 231 232 * thrown by code executing in this thread and was not caught. 232 233 */ 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); 244 235 245 236 /** … … 249 240 * @pre This thread was previously suspended using the suspend() member 250 241 * function. 251 * @post This thread is sent the SIGCONT signal and is allowed to begin242 * @post This thread is sent the \c SIGCONT signal and is allowed to begin 252 243 * executing again. 253 244 * 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. 256 247 * 257 248 * @note This is not currently supported on HP-UX 10.20. 258 249 */ 259 virtual intresume()260 { 261 returnkill(SIGCONT);250 virtual void resume() 251 { 252 this->kill(SIGCONT); 262 253 } 263 254 … … 265 256 * Suspends the execution of this thread. 266 257 * 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 268 260 * from execution until the member function resume() is called. 269 261 * 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. 272 264 * 273 265 * @note This is not currently supported on HP-UX 10.20. 274 266 */ 275 virtual intsuspend()276 { 277 returnkill(SIGSTOP);267 virtual void suspend() 268 { 269 this->kill(SIGSTOP); 278 270 } 279 271 … … 281 273 * Gets this thread's priority. 282 274 * 283 * @p ost The priority of this thread is returned in the integer pointer284 * variable.285 * 286 * @param prio Pointer to an int variable that will have the thread's287 * 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). 291 283 * 292 284 * @note This is only supported on systems that support thread priority 293 285 * scheduling in their pthreads implementation. 294 286 */ 295 virtual int getPrio(VPRThreadPriority* prio);287 virtual VPRThreadPriority getPrio(); 296 288 297 289 /** … … 302 294 * @param prio The new priority for this thread. 303 295 * 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. 306 299 * 307 300 * @note This is only supported on systems that support thread priority 308 301 * scheduling in their pthreads implementation. 309 302 */ 310 virtual int setPrio(VPRThreadPriority prio);303 virtual void setPrio(const VPRThreadPriority prio); 311 304 312 305 /** … … 319 312 * @param cpu The CPU on which this thread will run exclusively. 320 313 * 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. 323 316 * 324 317 * @note This is currently only available on IRIX 6.5 and is non-portable. 325 318 */ 326 virtual int setRunOn(int cpu);319 virtual void setRunOn(const int cpu); 327 320 328 321 /** … … 335 328 * pointer. 336 329 * 337 * @ param cur_cpu The CPU affinity for this thread (set by a previous338 * 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. 342 335 * 343 336 * @note This is currently only available on IRIX 6.5 and is non-portable. 344 337 */ 345 virtual int getRunOn( int* cur_cpu);338 virtual int getRunOn(); 346 339 347 340 /** … … 358 351 359 352 /** 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. 362 356 * @post This thread receives the specified signal. 363 357 * 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. 368 363 * 369 364 * @note This is not currently supported with Pthreads Draft 4. 370 365 */ 371 virtual int kill(int signum);366 virtual void kill(const int signum); 372 367 373 368 /** … … 379 374 * stop or it may ignore the cancel altogether. Thus, immediate 380 375 * cancellation is not guaranteed. 381 *382 * @note For the sake of clarity, it is probably better to use the383 * cancel() routine instead of kill() because a two-argument384 * version of kill() is also used for sending signals to threads.385 * This kill() and cancel() do exactly the same thing.386 376 */ 387 377 virtual void kill() juggler/trunk/modules/vapor/vpr/md/SPROC/Thread/ThreadSGI.cpp
r19333 r19650 204 204 * thread. 205 205 */ 206 int ThreadSGI::join(void** arg) 207 { 208 int status, retval; 206 void ThreadSGI::join(void** status) 207 { 209 208 pid_t pid; 210 209 211 210 do 212 211 { 213 pid = ::waitpid(mThreadPID, & status, 0);214 } while ( WIFSTOPPED( status) != 0 );212 pid = ::waitpid(mThreadPID, &exit_status, 0); 213 } while ( WIFSTOPPED(exit_status) != 0 ); 215 214 216 215 if ( pid > -1 ) … … 218 217 vprASSERT(pid == mThreadPID); 219 218 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 } 230 227 } 231 228 else 232 229 { 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 ) 237 235 { 238 236 throw mException; 239 237 } 240 241 return retval; 238 } 239 240 BaseThread::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 259 void 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 295 void 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
