Changes in src/libcfa/concurrency/kernel.c [9d944b2:17af7d1]
- File:
-
- 1 edited
-
src/libcfa/concurrency/kernel.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r9d944b2 r17af7d1 15 15 // 16 16 17 #include "startup.h"18 19 17 //Start and stop routine for the kernel, declared first to make sure they run first 20 void kernel_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_KERNEL )));21 void kernel_shutdown(void) __attribute__(( destructor ( STARTUP_PRIORITY_KERNEL )));18 void kernel_startup(void) __attribute__((constructor(101))); 19 void kernel_shutdown(void) __attribute__((destructor(101))); 22 20 23 21 //Header … … 27 25 #include <stddef.h> 28 26 extern "C" { 29 #include <stdio.h>30 27 #include <fenv.h> 31 28 #include <sys/resource.h> 32 #include <signal.h>33 #include <unistd.h>34 29 } 35 30 … … 151 146 152 147 this->runner = runner; 153 LIB_DEBUG_PRINT _SAFE("Kernel : constructing processor context %p\n", runner);148 LIB_DEBUG_PRINTF("Kernel : constructing processor context %p\n", runner); 154 149 runner{ this }; 155 150 } … … 157 152 void ^?{}(processor * this) { 158 153 if( ! this->is_terminated ) { 159 LIB_DEBUG_PRINT _SAFE("Kernel : core %p signaling termination\n", this);154 LIB_DEBUG_PRINTF("Kernel : core %p signaling termination\n", this); 160 155 this->is_terminated = true; 161 156 wait( &this->terminated ); … … 178 173 void main(processorCtx_t * runner) { 179 174 processor * this = runner->proc; 180 LIB_DEBUG_PRINT _SAFE("Kernel : core %p starting\n", this);175 LIB_DEBUG_PRINTF("Kernel : core %p starting\n", this); 181 176 182 177 thread_desc * readyThread = NULL; … … 200 195 } 201 196 202 LIB_DEBUG_PRINT _SAFE("Kernel : core %p unlocking thread\n", this);197 LIB_DEBUG_PRINTF("Kernel : core %p unlocking thread\n", this); 203 198 signal( &this->terminated ); 204 LIB_DEBUG_PRINT _SAFE("Kernel : core %p terminated\n", this);199 LIB_DEBUG_PRINTF("Kernel : core %p terminated\n", this); 205 200 } 206 201 … … 260 255 processorCtx_t proc_cor_storage = { proc, &info }; 261 256 262 LIB_DEBUG_PRINT _SAFE("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base);257 LIB_DEBUG_PRINTF("Coroutine : created stack %p\n", proc_cor_storage.__cor.stack.base); 263 258 264 259 //Set global state … … 267 262 268 263 //We now have a proper context from which to schedule threads 269 LIB_DEBUG_PRINT _SAFE("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx);264 LIB_DEBUG_PRINTF("Kernel : core %p created (%p, %p)\n", proc, proc->runner, &ctx); 270 265 271 266 // SKULLDUGGERY: Since the coroutine doesn't have its own stack, we can't … … 278 273 279 274 // Main routine of the core returned, the core is now fully terminated 280 LIB_DEBUG_PRINT _SAFE("Kernel : core %p main ended (%p)\n", proc, proc->runner);275 LIB_DEBUG_PRINTF("Kernel : core %p main ended (%p)\n", proc, proc->runner); 281 276 282 277 return NULL; … … 284 279 285 280 void start(processor * this) { 286 LIB_DEBUG_PRINT _SAFE("Kernel : Starting core %p\n", this);281 LIB_DEBUG_PRINTF("Kernel : Starting core %p\n", this); 287 282 288 283 // pthread_attr_t attributes; … … 293 288 // pthread_attr_destroy( &attributes ); 294 289 295 LIB_DEBUG_PRINT _SAFE("Kernel : core %p started\n", this);290 LIB_DEBUG_PRINTF("Kernel : core %p started\n", this); 296 291 } 297 292 … … 339 334 // Kernel boot procedures 340 335 void kernel_startup(void) { 341 LIB_DEBUG_PRINT _SAFE("Kernel : Starting\n");336 LIB_DEBUG_PRINTF("Kernel : Starting\n"); 342 337 343 338 // Start by initializing the main thread … … 374 369 375 370 // THE SYSTEM IS NOW COMPLETELY RUNNING 376 LIB_DEBUG_PRINT _SAFE("Kernel : Started\n--------------------------------------------------\n\n");371 LIB_DEBUG_PRINTF("Kernel : Started\n--------------------------------------------------\n\n"); 377 372 } 378 373 379 374 void kernel_shutdown(void) { 380 LIB_DEBUG_PRINT _SAFE("\n--------------------------------------------------\nKernel : Shutting down\n");375 LIB_DEBUG_PRINTF("\n--------------------------------------------------\nKernel : Shutting down\n"); 381 376 382 377 // SKULLDUGGERY: Notify the systemProcessor it needs to terminates. … … 397 392 ^(mainThread){}; 398 393 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 } 394 LIB_DEBUG_PRINTF("Kernel : Shutdown complete\n"); 453 395 } 454 396
Note:
See TracChangeset
for help on using the changeset viewer.