- File:
-
- 1 edited
-
libcfa/src/concurrency/preemption.cfa (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/preemption.cfa
r09d4b22 r2026bb6 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T hu Dec 5 16:34:05 201913 // Update Count : 4312 // 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 … … 65 64 event_kernel_t * event_kernel; // kernel public handle to even kernel 66 65 static pthread_t alarm_thread; // pthread handle to alarm thread 67 static void * alarm_stack; // pthread stack for alarm thread68 66 69 67 static void ?{}(event_kernel_t & this) with( this ) { … … 83 81 // Get next expired node 84 82 static inline alarm_node_t * get_expired( alarm_list_t * alarms, Time currtime ) { 85 if( !alarms->head ) return 0p;// If no alarms return null86 if( alarms->head->alarm >= currtime ) return 0p;// If alarms head not expired return null87 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 88 86 } 89 87 90 88 // Tick one frame of the Discrete Event Simulation for alarms 91 89 static void tick_preemption() { 92 alarm_node_t * node = 0p;// Used in the while loop but cannot be declared in the while condition93 alarm_list_t * alarms = &event_kernel->alarms; // Local copy for ease of reading94 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" 95 93 96 94 //Loop throught every thing expired … … 245 243 sigaddset( &mask, sig ); 246 244 247 if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p) == -1 ) {245 if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) { 248 246 abort( "internal error, pthread_sigmask" ); 249 247 } … … 256 254 sigaddset( &mask, sig ); 257 255 258 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p) == -1 ) {256 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { 259 257 abort( "internal error, pthread_sigmask" ); 260 258 } … … 303 301 304 302 // Setup proper signal handlers 305 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler303 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler 306 304 307 305 signal_block( SIGALRM ); 308 306 309 alarm_stack = create_pthread( &alarm_thread, alarm_loop, 0p);307 pthread_create( &alarm_thread, NULL, alarm_loop, NULL ); 310 308 } 311 309 … … 318 316 sigset_t mask; 319 317 sigfillset( &mask ); 320 sigprocmask( SIG_BLOCK, &mask, 0p);318 sigprocmask( SIG_BLOCK, &mask, NULL ); 321 319 322 320 // Notify the alarm thread of the shutdown … … 325 323 326 324 // Wait for the preemption thread to finish 327 328 pthread_join( alarm_thread, 0p ); 329 free( alarm_stack ); 325 pthread_join( alarm_thread, NULL ); 330 326 331 327 // Preemption is now fully stopped … … 384 380 static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" ); 385 381 #endif 386 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 ) { 387 383 abort( "internal error, sigprocmask" ); 388 384 } … … 403 399 sigset_t mask; 404 400 sigfillset(&mask); 405 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p) == -1 ) {401 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) { 406 402 abort( "internal error, pthread_sigmask" ); 407 403 } … … 424 420 {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );} 425 421 continue; 426 case EINVAL :422 case EINVAL : 427 423 abort( "Timeout was invalid." ); 428 424 default: … … 457 453 EXIT: 458 454 __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" ); 459 return 0p;455 return NULL; 460 456 } 461 457 … … 470 466 sigset_t oldset; 471 467 int ret; 472 ret = pthread_sigmask(0, 0p, &oldset);468 ret = pthread_sigmask(0, NULL, &oldset); 473 469 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 474 470
Note:
See TracChangeset
for help on using the changeset viewer.