Changes in src/libcfa/concurrency/kernel.c [690f13c:9d944b2]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/libcfa/concurrency/kernel.c ¶
r690f13c r9d944b2 15 15 // 16 16 17 #include "startup.h" 18 17 19 //Start and stop routine for the kernel, declared first to make sure they run first 18 void kernel_startup(void) __attribute__(( constructor(101)));19 void kernel_shutdown(void) __attribute__(( destructor(101)));20 void kernel_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_KERNEL ) )); 21 void kernel_shutdown(void) __attribute__(( destructor ( STARTUP_PRIORITY_KERNEL ) )); 20 22 21 23 //Header … … 25 27 #include <stddef.h> 26 28 extern "C" { 29 #include <stdio.h> 27 30 #include <fenv.h> 28 31 #include <sys/resource.h> 32 #include <signal.h> 33 #include <unistd.h> 29 34 } 30 35 … … 146 151 147 152 this->runner = runner; 148 LIB_DEBUG_PRINT F("Kernel : constructing processor context %p\n", runner);153 LIB_DEBUG_PRINT_SAFE("Kernel : constructing processor context %p\n", runner); 149 154 runner{ this }; 150 155 } … … 152 157 void ^?{}(processor * this) { 153 158 if( ! this->is_terminated ) { 154 LIB_DEBUG_PRINT F("Kernel : core %p signaling termination\n", this);159 LIB_DEBUG_PRINT_SAFE("Kernel : core %p signaling termination\n", this); 155 160 this->is_terminated = true; 156 161 wait( &this->terminated ); … … 173 178 void main(processorCtx_t * runner) { 174 179 processor * this = runner->proc; 175 LIB_DEBUG_PRINT F("Kernel : core %p starting\n", this);180 LIB_DEBUG_PRINT_SAFE("Kernel : core %p starting\n", this); 176 181 177 182 thread_desc * readyThread = NULL; … … 195 200 } 196 201 197 LIB_DEBUG_PRINT F("Kernel : core %p unlocking thread\n", this);202 LIB_DEBUG_PRINT_SAFE("Kernel : core %p unlocking thread\n", this); 198 203 signal( &this->terminated ); 199 LIB_DEBUG_PRINT F("Kernel : core %p terminated\n", this);204 LIB_DEBUG_PRINT_SAFE("Kernel : core %p terminated\n", this); 200 205 } 201 206 … … 255 260 processorCtx_t proc_cor_storage = { proc, &info }; 256 261 257 LIB_DEBUG_PRINT F("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);262 LIB_DEBUG_PRINT_SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base); 258 263 259 264 //Set global state … … 262 267 263 268 //We now have a proper context from which to schedule threads 264 LIB_DEBUG_PRINT F("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);269 LIB_DEBUG_PRINT_SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx); 265 270 266 271 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 273 278 274 279 // Main routine of the core returned, the core is now fully terminated 275 LIB_DEBUG_PRINT F("Kernel : core %p main ended (%p)\n", proc, proc->runner);280 LIB_DEBUG_PRINT_SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner); 276 281 277 282 return NULL; … … 279 284 280 285 void start(processor * this) { 281 LIB_DEBUG_PRINT F("Kernel : Starting core %p\n", this);286 LIB_DEBUG_PRINT_SAFE("Kernel : Starting core %p\n", this); 282 287 283 288 // pthread_attr_t attributes; … … 288 293 // pthread_attr_destroy( &attributes ); 289 294 290 LIB_DEBUG_PRINT F("Kernel : core %p started\n", this);295 LIB_DEBUG_PRINT_SAFE("Kernel : core %p started\n", this); 291 296 } 292 297 … … 294 299 // Scheduler routines 295 300 void ScheduleThread( thread_desc * thrd ) { 296 if( !thrd ) return;297 298 301 assertf( thrd->next == NULL, "Expected null got %p", thrd->next ); 299 302 … … 336 339 // Kernel boot procedures 337 340 void kernel_startup(void) { 338 LIB_DEBUG_PRINT F("Kernel : Starting\n");341 LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n"); 339 342 340 343 // Start by initializing the main thread … … 371 374 372 375 // THE SYSTEM IS NOW COMPLETELY RUNNING 373 LIB_DEBUG_PRINT F("Kernel : Started\n--------------------------------------------------\n\n");376 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n"); 374 377 } 375 378 376 379 void kernel_shutdown(void) { 377 LIB_DEBUG_PRINT F("\n--------------------------------------------------\nKernel : Shutting down\n");380 LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n"); 378 381 379 382 // SKULLDUGGERY: Notify the systemProcessor it needs to terminates. … … 394 397 ^(mainThread){}; 395 398 396 LIB_DEBUG_PRINTF("Kernel : Shutdown complete\n"); 399 LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n"); 400 } 401 402 static spinlock kernel_abort_lock; 403 static spinlock kernel_debug_lock; 404 static bool kernel_abort_called = false; 405 406 void * kernel_abort (void) __attribute__ ((__nothrow__)) { 407 // abort cannot be recursively entered by the same or different processors because all signal handlers return when 408 // the globalAbort flag is true. 409 lock( &kernel_abort_lock ); 410 411 // first task to abort ? 412 if ( !kernel_abort_called ) { // not first task to abort ? 413 kernel_abort_called = true; 414 unlock( &kernel_abort_lock ); 415 } 416 else { 417 unlock( &kernel_abort_lock ); 418 419 sigset_t mask; 420 sigemptyset( &mask ); 421 sigaddset( &mask, SIGALRM ); // block SIGALRM signals 422 sigaddset( &mask, SIGUSR1 ); // block SIGUSR1 signals 423 sigsuspend( &mask ); // block the processor to prevent further damage during abort 424 _exit( EXIT_FAILURE ); // if processor unblocks before it is killed, terminate it 425 } 426 427 return this_thread(); 428 } 429 430 void kernel_abort_msg( void * kernel_data, char * abort_text, int abort_text_size ) { 431 thread_desc * thrd = kernel_data; 432 433 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->cor.name, thrd ); 434 __lib_debug_write( STDERR_FILENO, abort_text, len ); 435 436 if ( thrd != this_coroutine() ) { 437 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine()->name, this_coroutine() ); 438 __lib_debug_write( STDERR_FILENO, abort_text, len ); 439 } 440 else { 441 __lib_debug_write( STDERR_FILENO, ".\n", 2 ); 442 } 443 } 444 445 extern "C" { 446 void __lib_debug_acquire() { 447 lock(&kernel_debug_lock); 448 } 449 450 void __lib_debug_release() { 451 unlock(&kernel_debug_lock); 452 } 397 453 } 398 454 … … 470 526 return head; 471 527 } 472 473 void ?{}( simple_thread_stack * this ) {474 this->top = NULL;475 }476 477 void push( simple_thread_stack * this, thread_desc * t ) {478 assert(t->next != NULL);479 t->next = this->top;480 this->top = t;481 }482 483 thread_desc * pop( simple_thread_stack * this ) {484 thread_desc * top = this->top;485 if( top ) {486 this->top = top->next;487 top->next = NULL;488 }489 return top;490 }491 528 // Local Variables: // 492 529 // mode: c //
Note: See TracChangeset
for help on using the changeset viewer.