Changeset 78d3dd5 for src/libcfa/concurrency
- Timestamp:
- Mar 31, 2017, 12:24:39 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:
- 5ea06d6
- Parents:
- 72dc82a (diff), 077810d (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. - Location:
- src/libcfa/concurrency
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/concurrency/kernel.c
r72dc82a r78d3dd5 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 … … 336 341 // Kernel boot procedures 337 342 void kernel_startup(void) { 338 LIB_DEBUG_PRINT F("Kernel : Starting\n");343 LIB_DEBUG_PRINT_SAFE("Kernel : Starting\n"); 339 344 340 345 // Start by initializing the main thread … … 371 376 372 377 // THE SYSTEM IS NOW COMPLETELY RUNNING 373 LIB_DEBUG_PRINT F("Kernel : Started\n--------------------------------------------------\n\n");378 LIB_DEBUG_PRINT_SAFE("Kernel : Started\n--------------------------------------------------\n\n"); 374 379 } 375 380 376 381 void kernel_shutdown(void) { 377 LIB_DEBUG_PRINT F("\n--------------------------------------------------\nKernel : Shutting down\n");382 LIB_DEBUG_PRINT_SAFE("\n--------------------------------------------------\nKernel : Shutting down\n"); 378 383 379 384 // SKULLDUGGERY: Notify the systemProcessor it needs to terminates. … … 394 399 ^(mainThread){}; 395 400 396 LIB_DEBUG_PRINTF("Kernel : Shutdown complete\n"); 401 LIB_DEBUG_PRINT_SAFE("Kernel : Shutdown complete\n"); 402 } 403 404 static spinlock kernel_abort_lock; 405 static spinlock kernel_debug_lock; 406 static bool kernel_abort_called = false; 407 408 void * kernel_abort (void) __attribute__ ((__nothrow__)) { 409 // abort cannot be recursively entered by the same or different processors because all signal handlers return when 410 // the globalAbort flag is true. 411 lock( &kernel_abort_lock ); 412 413 // first task to abort ? 414 if ( !kernel_abort_called ) { // not first task to abort ? 415 kernel_abort_called = true; 416 unlock( &kernel_abort_lock ); 417 } 418 else { 419 unlock( &kernel_abort_lock ); 420 421 sigset_t mask; 422 sigemptyset( &mask ); 423 sigaddset( &mask, SIGALRM ); // block SIGALRM signals 424 sigaddset( &mask, SIGUSR1 ); // block SIGUSR1 signals 425 sigsuspend( &mask ); // block the processor to prevent further damage during abort 426 _exit( EXIT_FAILURE ); // if processor unblocks before it is killed, terminate it 427 } 428 429 return this_thread(); 430 } 431 432 void kernel_abort_msg( void * kernel_data, char * abort_text, int abort_text_size ) { 433 thread_desc * thrd = kernel_data; 434 435 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->cor.name, thrd ); 436 __lib_debug_write( STDERR_FILENO, abort_text, len ); 437 438 if ( thrd != this_coroutine() ) { 439 len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", this_coroutine()->name, this_coroutine() ); 440 __lib_debug_write( STDERR_FILENO, abort_text, len ); 441 } 442 else { 443 __lib_debug_write( STDERR_FILENO, ".\n", 2 ); 444 } 445 } 446 447 extern "C" { 448 void __lib_debug_acquire() { 449 lock(&kernel_debug_lock); 450 } 451 452 void __lib_debug_release() { 453 unlock(&kernel_debug_lock); 454 } 397 455 } 398 456 -
src/libcfa/concurrency/thread.c
r72dc82a r78d3dd5 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.