Changeset 266ecf1 for libcfa/src/concurrency/kernel/startup.cfa
- Timestamp:
- Mar 2, 2021, 5:28:32 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 6083392
- Parents:
- 182256b (diff), 9eb7a532 (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/kernel/startup.cfa
r182256b r266ecf1 22 22 extern "C" { 23 23 #include <limits.h> // PTHREAD_STACK_MIN 24 #include <sys/eventfd.h> // eventfd 24 25 #include <sys/mman.h> // mprotect 25 26 #include <sys/resource.h> // getrlimit … … 80 81 static void ?{}(processorCtx_t & this) {} 81 82 static void ?{}(processorCtx_t & this, processor * proc, current_stack_info_t * info); 82 static void ?{}(__bin_sem_t & this);83 static void ^?{}(__bin_sem_t & this);84 83 85 84 #if defined(__CFA_WITH_VERIFY__) … … 91 90 extern void __kernel_alarm_startup(void); 92 91 extern void __kernel_alarm_shutdown(void); 93 extern void __kernel_io_startup (void);94 extern void __kernel_io_shutdown(void);95 92 96 93 //----------------------------------------------------------------------------- … … 104 101 KERNEL_STORAGE($thread, mainThread); 105 102 KERNEL_STORAGE(__stack_t, mainThreadCtx); 106 KERNEL_STORAGE(io_context, mainPollerThread);107 103 KERNEL_STORAGE(__scheduler_RWLock_t, __scheduler_lock); 108 104 #if !defined(__CFA_NO_STATISTICS__) … … 200 196 201 197 void ?{}(processor & this) with( this ) { 202 ( this.idle ){};203 198 ( this.terminated ){}; 204 199 ( this.runner ){}; … … 228 223 __kernel_alarm_startup(); 229 224 230 // Start IO231 __kernel_io_startup();232 233 225 // Add the main thread to the ready queue 234 226 // once resume is called on mainProcessor->runner the mainThread needs to be scheduled like any normal thread … … 243 235 // THE SYSTEM IS NOW COMPLETELY RUNNING 244 236 245 246 // SKULLDUGGERY: The constructor for the mainCluster will call alloc with a dimension of 0247 // malloc *can* return a non-null value, we should free it if that is the case248 free( mainCluster->io.ctxs );249 250 // Now that the system is up, finish creating systems that need threading251 mainCluster->io.ctxs = (io_context *)&storage_mainPollerThread;252 mainCluster->io.cnt = 1;253 (*mainCluster->io.ctxs){ *mainCluster };254 255 237 __cfadbg_print_safe(runtime_core, "Kernel : Started\n--------------------------------------------------\n\n"); 256 238 … … 262 244 263 245 static void __kernel_shutdown(void) { 264 //Before we start shutting things down, wait for systems that need threading to shutdown265 ^(*mainCluster->io.ctxs){};266 mainCluster->io.cnt = 0;267 mainCluster->io.ctxs = 0p;268 269 246 /* paranoid */ verify( __preemption_enabled() ); 270 247 disable_interrupts(); … … 284 261 // Disable preemption 285 262 __kernel_alarm_shutdown(); 286 287 // Stop IO288 __kernel_io_shutdown();289 263 290 264 // Destroy the main processor and its context in reverse order of construction … … 486 460 pending_preemption = false; 487 461 462 this.io.ctx = 0p; 463 this.io.pending = false; 464 this.io.dirty = false; 465 466 this.idle = eventfd(0, 0); 467 if (idle < 0) { 468 abort("KERNEL ERROR: PROCESSOR EVENTFD - %s\n", strerror(errno)); 469 } 470 488 471 #if !defined(__CFA_NO_STATISTICS__) 489 472 print_stats = 0; … … 526 509 // Finally we don't need the read_lock any more 527 510 unregister((__processor_id_t*)&this); 511 512 close(this.idle); 528 513 } 529 514 530 515 void ?{}(processor & this, const char name[], cluster & _cltr) { 531 ( this.idle ){};532 516 ( this.terminated ){}; 533 517 ( this.runner ){}; … … 584 568 threads{ __get }; 585 569 570 io.arbiter = create(); 571 io.params = io_params; 572 586 573 doregister(this); 587 574 … … 596 583 ready_mutate_unlock( last_size ); 597 584 enable_interrupts_noPoll(); // Don't poll, could be in main cluster 598 599 600 this.io.cnt = num_io;601 this.io.ctxs = aalloc(num_io);602 for(i; this.io.cnt) {603 (this.io.ctxs[i]){ this, io_params };604 }605 585 } 606 586 607 587 void ^?{}(cluster & this) { 608 for(i; this.io.cnt) { 609 ^(this.io.ctxs[i]){ true }; 610 } 611 free(this.io.ctxs); 588 destroy(this.io.arbiter); 612 589 613 590 // Lock the RWlock so no-one pushes/pops while we are changing the queue … … 738 715 } 739 716 740 extern "C" {741 char * strerror(int);742 }743 #define CHECKED(x) { int err = x; if( err != 0 ) abort("KERNEL ERROR: Operation \"" #x "\" return error %d - %s\n", err, strerror(err)); }744 745 static void ?{}(__bin_sem_t & this) with( this ) {746 // Create the mutex with error checking747 pthread_mutexattr_t mattr;748 pthread_mutexattr_init( &mattr );749 pthread_mutexattr_settype( &mattr, PTHREAD_MUTEX_ERRORCHECK_NP);750 pthread_mutex_init(&lock, &mattr);751 752 pthread_cond_init (&cond, (const pthread_condattr_t *)0p); // workaround trac#208: cast should not be required753 val = 0;754 }755 756 static void ^?{}(__bin_sem_t & this) with( this ) {757 CHECKED( pthread_mutex_destroy(&lock) );758 CHECKED( pthread_cond_destroy (&cond) );759 }760 761 #undef CHECKED762 763 717 #if defined(__CFA_WITH_VERIFY__) 764 718 static bool verify_fwd_bck_rng(void) {
Note: See TracChangeset
for help on using the changeset viewer.