Changeset 9d944b2 for src/libcfa/concurrency
- Timestamp:
- Mar 31, 2017, 12:16:14 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 077810d
- Parents:
- 95448f1e
- Location:
- src/libcfa/concurrency
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r95448f1e 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 … … 334 339 // Kernel boot procedures 335 340 void kernel_startup(void) { 336 LIB_DEBUG_PRINT F("Kernel : Starting\n");341 LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n"); 337 342 338 343 // Start by initializing the main thread … … 369 374 370 375 // THE SYSTEM IS NOW COMPLETELY RUNNING 371 LIB_DEBUG_PRINT F("Kernel : Started\n--------------------------------------------------\n\n");376 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n"); 372 377 } 373 378 374 379 void kernel_shutdown(void) { 375 LIB_DEBUG_PRINT F("\n--------------------------------------------------\nKernel : Shutting down\n");380 LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n"); 376 381 377 382 // SKULLDUGGERY: Notify the systemProcessor it needs to terminates. … … 392 397 ^(mainThread){}; 393 398 394 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 } 395 453 } 396 454 -
src/libcfa/concurrency/thread.c
r95448f1e r9d944b2 71 71 this_processor->current_coroutine = thrd_c; 72 72 73 LIB_DEBUG_PRINT F("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h);73 LIB_DEBUG_PRINT_SAFE("Thread start : %p (t %p, c %p)\n", this, thrd_c, thrd_h); 74 74 75 75 create_stack(&thrd_c->stack, thrd_c->stack.size);
Note: See TracChangeset
for help on using the changeset viewer.