- File:
-
- 1 edited
-
libcfa/src/concurrency/preemption.cfa (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/preemption.cfa
r27f5f71 r2026bb6 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Nov 30 08:02:56 201913 // Update Count : 3 912 // Last Modified On : Tue Jun 5 17:35:49 2018 13 // Update Count : 37 14 14 // 15 15 … … 24 24 #include <string.h> 25 25 #include <unistd.h> 26 #include <limits.h> // PTHREAD_STACK_MIN27 26 } 28 27 … … 82 81 // Get next expired node 83 82 static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) { 84 if( !alarms->head ) return 0p;// If no alarms return null85 if( alarms->head->alarm >= currtime ) return 0p;// If alarms head not expired return null86 return pop(alarms); // Otherwise just pop head83 if( !alarms->head ) return NULL; // If no alarms return null 84 if( alarms->head->alarm >= currtime ) return NULL; // If alarms head not expired return null 85 return pop(alarms); // Otherwise just pop head 87 86 } 88 87 89 88 // Tick one frame of the Discrete Event Simulation for alarms 90 89 static void tick_preemption() { 91 alarm_node_t * node = 0p;// Used in the while loop but cannot be declared in the while condition92 alarm_list_t * alarms = &event_kernel->alarms; // Local copy for ease of reading93 Time currtime = __kernel_get_time(); // Check current time once soeverything "happens at once"90 alarm_node_t * node = NULL; // Used in the while loop but cannot be declared in the while condition 91 alarm_list_t * alarms = &event_kernel->alarms; // Local copy for ease of reading 92 Time currtime = __kernel_get_time(); // Check current time once so we everything "happens at once" 94 93 95 94 //Loop throught every thing expired … … 244 243 sigaddset( &mask, sig ); 245 244 246 if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p) == -1 ) {245 if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) { 247 246 abort( "internal error, pthread_sigmask" ); 248 247 } … … 255 254 sigaddset( &mask, sig ); 256 255 257 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p) == -1 ) {256 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { 258 257 abort( "internal error, pthread_sigmask" ); 259 258 } … … 302 301 303 302 // Setup proper signal handlers 304 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler303 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler 305 304 306 305 signal_block( SIGALRM ); 307 306 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 307 pthread_create( &alarm_thread, NULL, alarm_loop, NULL ); 332 308 } 333 309 … … 340 316 sigset_t mask; 341 317 sigfillset( &mask ); 342 sigprocmask( SIG_BLOCK, &mask, 0p);318 sigprocmask( SIG_BLOCK, &mask, NULL ); 343 319 344 320 // Notify the alarm thread of the shutdown … … 347 323 348 324 // Wait for the preemption thread to finish 349 350 pthread_join( alarm_thread, 0p ); 351 free( kernelTLS.preemption_state.stack ); 325 pthread_join( alarm_thread, NULL ); 352 326 353 327 // Preemption is now fully stopped … … 406 380 static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" ); 407 381 #endif 408 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p) == -1 ) {382 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL ) == -1 ) { 409 383 abort( "internal error, sigprocmask" ); 410 384 } … … 425 399 sigset_t mask; 426 400 sigfillset(&mask); 427 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p) == -1 ) {401 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { 428 402 abort( "internal error, pthread_sigmask" ); 429 403 } … … 446 420 {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );} 447 421 continue; 448 case EINVAL :422 case EINVAL : 449 423 abort( "Timeout was invalid." ); 450 424 default: … … 479 453 EXIT: 480 454 __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" ); 481 return 0p;455 return NULL; 482 456 } 483 457 … … 492 466 sigset_t oldset; 493 467 int ret; 494 ret = pthread_sigmask(0, 0p, &oldset);468 ret = pthread_sigmask(0, NULL, &oldset); 495 469 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 496 470
Note:
See TracChangeset
for help on using the changeset viewer.