Changeset 27f5f71 for libcfa/src/concurrency/preemption.cfa
- Timestamp:
- Nov 30, 2019, 11:08:34 AM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 4cae032
- Parents:
- 524627e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/preemption.cfa
r524627e r27f5f71 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jun 5 17:35:49 201813 // Update Count : 3 712 // Last Modified On : Sat Nov 30 08:02:56 2019 13 // Update Count : 39 14 14 // 15 15 … … 24 24 #include <string.h> 25 25 #include <unistd.h> 26 #include <limits.h> // PTHREAD_STACK_MIN 26 27 } 27 28 … … 81 82 // Get next expired node 82 83 static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) { 83 if( !alarms->head ) return NULL;// If no alarms return null84 if( alarms->head->alarm >= currtime ) return NULL;// If alarms head not expired return null85 return pop(alarms); 84 if( !alarms->head ) return 0p; // If no alarms return null 85 if( alarms->head->alarm >= currtime ) return 0p; // If alarms head not expired return null 86 return pop(alarms); // Otherwise just pop head 86 87 } 87 88 88 89 // Tick one frame of the Discrete Event Simulation for alarms 89 90 static void tick_preemption() { 90 alarm_node_t * node = NULL;// Used in the while loop but cannot be declared in the while condition91 alarm_list_t * alarms = &event_kernel->alarms; 92 Time currtime = __kernel_get_time(); // Check current time once so weeverything "happens at once"91 alarm_node_t * node = 0p; // Used in the while loop but cannot be declared in the while condition 92 alarm_list_t * alarms = &event_kernel->alarms; // Local copy for ease of reading 93 Time currtime = __kernel_get_time(); // Check current time once so everything "happens at once" 93 94 94 95 //Loop throught every thing expired … … 243 244 sigaddset( &mask, sig ); 244 245 245 if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL) == -1 ) {246 if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) { 246 247 abort( "internal error, pthread_sigmask" ); 247 248 } … … 254 255 sigaddset( &mask, sig ); 255 256 256 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL) == -1 ) {257 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) { 257 258 abort( "internal error, pthread_sigmask" ); 258 259 } … … 301 302 302 303 // Setup proper signal handlers 303 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); 304 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler 304 305 305 306 signal_block( SIGALRM ); 306 307 307 pthread_create( &alarm_thread, NULL, alarm_loop, NULL ); 308 pthread_attr_t attr; 309 int ret; 310 ret = pthread_attr_init( &attr ); // initialize attribute 311 if ( ret ) { 312 abort( "%s : internal error, pthread_attr_init failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 313 } // if 314 315 size_t stacksize; 316 ret = pthread_attr_getstacksize( &attr, &stacksize ); // default stack size, normally defined by shell limit 317 if ( ret ) { 318 abort( "%s : internal error, pthread_attr_getstacksize failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 319 } // if 320 assert( stacksize >= PTHREAD_STACK_MIN ); 321 322 kernelTLS.preemption_state.stack = malloc( stacksize ); 323 ret = pthread_attr_setstack( &attr, kernelTLS.preemption_state.stack, stacksize ); 324 if ( ret ) { 325 abort( "%s : internal error, pthread_attr_setstack failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 326 } // if 327 328 ret = pthread_create( &alarm_thread, &attr, alarm_loop, 0p ); 329 if ( ret ) { 330 abort( "%s : internal error, pthread_create failed, error(%d) %s.", __PRETTY_FUNCTION__, ret, strerror( ret ) ); 331 } // if 308 332 } 309 333 … … 316 340 sigset_t mask; 317 341 sigfillset( &mask ); 318 sigprocmask( SIG_BLOCK, &mask, NULL);342 sigprocmask( SIG_BLOCK, &mask, 0p ); 319 343 320 344 // Notify the alarm thread of the shutdown … … 323 347 324 348 // Wait for the preemption thread to finish 325 pthread_join( alarm_thread, NULL ); 349 350 pthread_join( alarm_thread, 0p ); 351 free( kernelTLS.preemption_state.stack ); 326 352 327 353 // Preemption is now fully stopped … … 380 406 static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" ); 381 407 #endif 382 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL) == -1 ) {408 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) { 383 409 abort( "internal error, sigprocmask" ); 384 410 } … … 399 425 sigset_t mask; 400 426 sigfillset(&mask); 401 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL) == -1 ) {427 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) { 402 428 abort( "internal error, pthread_sigmask" ); 403 429 } … … 420 446 {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );} 421 447 continue; 422 448 case EINVAL : 423 449 abort( "Timeout was invalid." ); 424 450 default: … … 453 479 EXIT: 454 480 __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" ); 455 return NULL;481 return 0p; 456 482 } 457 483 … … 466 492 sigset_t oldset; 467 493 int ret; 468 ret = pthread_sigmask(0, NULL, &oldset);494 ret = pthread_sigmask(0, 0p, &oldset); 469 495 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 470 496
Note: See TracChangeset
for help on using the changeset viewer.