Changeset f80f840 for libcfa/src/concurrency/preemption.cfa
- Timestamp:
- Dec 10, 2019, 4:24:49 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 2a3d446
- Parents:
- b798713 (diff), e307e12 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/preemption.cfa
rb798713 rf80f840 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Jun 5 17:35:49 201813 // Update Count : 3712 // Last Modified On : Thu Dec 5 16:34:05 2019 13 // Update Count : 43 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 … … 64 65 event_kernel_t * event_kernel; // kernel public handle to even kernel 65 66 static pthread_t alarm_thread; // pthread handle to alarm thread 67 static void * alarm_stack; // pthread stack for alarm thread 66 68 67 69 static void ?{}(event_kernel_t & this) with( this ) { … … 81 83 // Get next expired node 82 84 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); 85 if( !alarms->head ) return 0p; // If no alarms return null 86 if( alarms->head->alarm >= currtime ) return 0p; // If alarms head not expired return null 87 return pop(alarms); // Otherwise just pop head 86 88 } 87 89 88 90 // Tick one frame of the Discrete Event Simulation for alarms 89 91 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"92 alarm_node_t * node = 0p; // Used in the while loop but cannot be declared in the while condition 93 alarm_list_t * alarms = &event_kernel->alarms; // Local copy for ease of reading 94 Time currtime = __kernel_get_time(); // Check current time once so everything "happens at once" 93 95 94 96 //Loop throught every thing expired … … 243 245 sigaddset( &mask, sig ); 244 246 245 if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL) == -1 ) {247 if ( pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) { 246 248 abort( "internal error, pthread_sigmask" ); 247 249 } … … 254 256 sigaddset( &mask, sig ); 255 257 256 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL) == -1 ) {258 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) { 257 259 abort( "internal error, pthread_sigmask" ); 258 260 } … … 301 303 302 304 // Setup proper signal handlers 303 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); 305 __cfaabi_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler 304 306 305 307 signal_block( SIGALRM ); 306 308 307 pthread_create( &alarm_thread, NULL, alarm_loop, NULL);309 alarm_stack = create_pthread( &alarm_thread, alarm_loop, 0p ); 308 310 } 309 311 … … 316 318 sigset_t mask; 317 319 sigfillset( &mask ); 318 sigprocmask( SIG_BLOCK, &mask, NULL);320 sigprocmask( SIG_BLOCK, &mask, 0p ); 319 321 320 322 // Notify the alarm thread of the shutdown … … 323 325 324 326 // Wait for the preemption thread to finish 325 pthread_join( alarm_thread, NULL ); 327 328 pthread_join( alarm_thread, 0p ); 329 free( alarm_stack ); 326 330 327 331 // Preemption is now fully stopped … … 380 384 static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" ); 381 385 #endif 382 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), NULL) == -1 ) {386 if ( pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) { 383 387 abort( "internal error, sigprocmask" ); 384 388 } … … 399 403 sigset_t mask; 400 404 sigfillset(&mask); 401 if ( pthread_sigmask( SIG_BLOCK, &mask, NULL) == -1 ) {405 if ( pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) { 402 406 abort( "internal error, pthread_sigmask" ); 403 407 } … … 420 424 {__cfaabi_dbg_print_buffer_decl( " KERNEL: Spurious wakeup %d.\n", err );} 421 425 continue; 422 426 case EINVAL : 423 427 abort( "Timeout was invalid." ); 424 428 default: … … 453 457 EXIT: 454 458 __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" ); 455 return NULL;459 return 0p; 456 460 } 457 461 … … 466 470 sigset_t oldset; 467 471 int ret; 468 ret = pthread_sigmask(0, NULL, &oldset);472 ret = pthread_sigmask(0, 0p, &oldset); 469 473 if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); } 470 474
Note: See TracChangeset
for help on using the changeset viewer.