Ignore:
Timestamp:
Oct 28, 2022, 3:12:16 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master
Children:
fa2e183
Parents:
e874605 (diff), 22a0e87 (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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/startup.cfa

    re874605 r93d2219  
    1616#define __cforall_thread__
    1717#define _GNU_SOURCE
     18
     19// #define __CFA_DEBUG_PRINT_RUNTIME_CORE__
    1820
    1921// C Includes
     
    222224                ( this.runner ){};
    223225                init( this, "Main Processor", *mainCluster, 0p );
    224                 kernel_thread = pthread_self();
     226                kernel_thread = __cfaabi_pthread_self();
    225227
    226228                runner{ &this };
     
    283285}
    284286
     287extern "C"{
     288        void pthread_delete_kernel_threads_();
     289}
     290
     291
    285292static void __kernel_shutdown(void) {
    286293        if(!cfa_main_returned) return;
     294
     295        //delete kernel threads for pthread_concurrency
     296        pthread_delete_kernel_threads_();
     297
    287298        /* paranoid */ verify( __preemption_enabled() );
    288299        disable_interrupts();
     
    327338
    328339                /* paranoid */ verify( this.do_terminate == true );
    329                 __cfaabi_dbg_print_safe("Kernel : destroyed main processor context %p\n", &runner);
     340                __cfadbg_print_safe(runtime_core, "Kernel : destroyed main processor context %p\n", &runner);
    330341        }
    331342
     
    388399        (proc->runner){ proc, &info };
    389400
    390         __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage);
     401        __cfadbg_print_safe(runtime_core, "Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage);
    391402
    392403        //Set global state
     
    520531        random_state = __global_random_mask ? __global_random_prime : __global_random_prime ^ rdtscl();
    521532        #if defined( __CFA_WITH_VERIFY__ )
     533                executing = 0p;
    522534                canary = 0x0D15EA5E0D15EA5Ep;
    523535        #endif
     
    652664        io.params = io_params;
    653665
     666        managed.procs = 0p;
     667        managed.cnt = 0;
     668
    654669        doregister(this);
    655670
     
    667682
    668683void ^?{}(cluster & this) libcfa_public {
     684        set_concurrency( this, 0 );
     685
    669686        destroy(this.io.arbiter);
    670687
     
    777794        pthread_attr_t attr;
    778795
    779         check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
     796        check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    780797
    781798        size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE );
     
    804821        #endif
    805822
    806         check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
    807         check( pthread_create( pthread, &attr, start, arg ), "pthread_create" );
     823        check( __cfaabi_pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
     824        check( __cfaabi_pthread_create( pthread, &attr, start, arg ), "pthread_create" );
    808825        return stack;
    809826}
    810827
    811828void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) {
    812         int err = pthread_join( pthread, retval );
     829        int err = __cfaabi_pthread_join( pthread, retval );
    813830        if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err));
    814831
     
    816833                pthread_attr_t attr;
    817834
    818                 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
     835                check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    819836
    820837                size_t stacksize;
    821838                // default stack size, normally defined by shell limit
    822                 check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );
     839                check( __cfaabi_pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );
    823840                assert( stacksize >= PTHREAD_STACK_MIN );
    824841                stacksize += __page_size;
     
    838855}
    839856
     857unsigned set_concurrency( cluster & this, unsigned new ) libcfa_public {
     858        unsigned old = this.managed.cnt;
     859
     860        __cfadbg_print_safe(runtime_core, "Kernel : resizing cluster from %u to %u\n", old, (unsigned)new);
     861
     862        // Delete all the old unneeded procs
     863        if(old > new) for(i; (unsigned)new ~ old) {
     864                __cfadbg_print_safe(runtime_core, "Kernel : destroying %u\n", i);
     865                delete( this.managed.procs[i] );
     866        }
     867
     868        // Allocate new array (uses realloc and memcpies the data)
     869        this.managed.procs = alloc( new, this.managed.procs`realloc );
     870        this.managed.cnt = new;
     871
     872        // Create the desired new procs
     873        if(old < new) for(i; old ~ new) {
     874                __cfadbg_print_safe(runtime_core, "Kernel : constructing %u\n", i);
     875                (*(this.managed.procs[i] = alloc())){ this };
     876        }
     877
     878        // return the old count
     879        return old;
     880}
     881
    840882#if defined(__CFA_WITH_VERIFY__)
    841883static bool verify_fwd_bck_rng(void) {
Note: See TracChangeset for help on using the changeset viewer.