Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/kernel.c

    rde94a60 rafd550c  
    4949thread_desc * mainThread;
    5050
    51 struct { __dllist_t(thread_desc) list; __spinlock_t lock; } global_threads ;
    52 struct { __dllist_t(cluster    ) list; __spinlock_t lock; } global_clusters;
    53 
    5451//-----------------------------------------------------------------------------
    5552// Global state
     
    120117        self_mon_p = &self_mon;
    121118        next = NULL;
    122 
    123         node.next = NULL;
    124         node.prev = NULL;
    125         doregister(this);
     119        __cfaabi_dbg_debug_do(
     120                dbg_next = NULL;
     121                dbg_prev = NULL;
     122                __cfaabi_dbg_thread_register(&this);
     123        )
    126124
    127125        monitors{ &self_mon_p, 1, (fptr_t)0 };
     
    169167        ready_queue{};
    170168        ready_queue_lock{};
    171 
    172         procs{ __get };
    173         idles{ __get };
    174 
    175         doregister(this);
    176169}
    177170
    178171void ^?{}(cluster & this) {
    179         unregister(this);
     172
    180173}
    181174
     
    189182
    190183        __cfaabi_dbg_print_safe("Kernel : core %p starting\n", this);
    191 
    192         doregister(this->cltr, this);
    193184
    194185        {
     
    224215                __cfaabi_dbg_print_safe("Kernel : core %p stopping\n", this);
    225216        }
    226 
    227         unregister(this->cltr, this);
    228217
    229218        V( this->terminated );
     
    523512        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    524513
    525         global_threads. list{ __get };
    526         global_threads. lock{};
    527         global_clusters.list{ __get };
    528         global_clusters.lock{};
    529 
    530514        // Initialize the main cluster
    531515        mainCluster = (cluster *)&storage_mainCluster;
     
    655639
    656640static __spinlock_t kernel_abort_lock;
     641static __spinlock_t kernel_debug_lock;
    657642static bool kernel_abort_called = false;
    658643
     
    663648
    664649        // first task to abort ?
    665         if ( kernel_abort_called ) {                    // not first task to abort ?
     650        if ( ! kernel_abort_called ) {                  // not first task to abort ?
     651                kernel_abort_called = true;
     652                unlock( kernel_abort_lock );
     653        }
     654        else {
    666655                unlock( kernel_abort_lock );
    667656
    668657                sigset_t mask;
    669658                sigemptyset( &mask );
    670                 sigaddset( &mask, SIGALRM );            // block SIGALRM signals
    671                 sigsuspend( &mask );                    // block the processor to prevent further damage during abort
    672                 _exit( EXIT_FAILURE );                  // if processor unblocks before it is killed, terminate it
    673         }
    674         else {
    675                 kernel_abort_called = true;
    676                 unlock( kernel_abort_lock );
     659                sigaddset( &mask, SIGALRM );                    // block SIGALRM signals
     660                sigaddset( &mask, SIGUSR1 );                    // block SIGUSR1 signals
     661                sigsuspend( &mask );                            // block the processor to prevent further damage during abort
     662                _exit( EXIT_FAILURE );                          // if processor unblocks before it is killed, terminate it
    677663        }
    678664
     
    683669        thread_desc * thrd = kernel_data;
    684670
    685         if(thrd) {
    686                 int len = snprintf( abort_text, abort_text_size, "Error occurred while executing thread %.256s (%p)", thrd->self_cor.name, thrd );
     671        int len = snprintf( abort_text, abort_text_size, "Error occurred while executing task %.256s (%p)", thrd->self_cor.name, thrd );
     672        __cfaabi_dbg_bits_write( abort_text, len );
     673
     674        if ( get_coroutine(thrd) != kernelTLS.this_coroutine ) {
     675                len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", kernelTLS.this_coroutine->name, kernelTLS.this_coroutine );
    687676                __cfaabi_dbg_bits_write( abort_text, len );
    688 
    689                 if ( get_coroutine(thrd) != kernelTLS.this_coroutine ) {
    690                         len = snprintf( abort_text, abort_text_size, " in coroutine %.256s (%p).\n", kernelTLS.this_coroutine->name, kernelTLS.this_coroutine );
    691                         __cfaabi_dbg_bits_write( abort_text, len );
    692                 }
    693                 else {
    694                         __cfaabi_dbg_bits_write( ".\n", 2 );
    695                 }
    696677        }
    697678        else {
    698                 int len = snprintf( abort_text, abort_text_size, "Error occurred outside of any thread.\n" );
     679                __cfaabi_dbg_bits_write( ".\n", 2 );
    699680        }
    700681}
     
    703684        return get_coroutine(kernelTLS.this_thread) == get_coroutine(mainThread) ? 4 : 2;
    704685}
    705 
    706 static __spinlock_t kernel_debug_lock;
    707686
    708687extern "C" {
     
    759738
    760739//-----------------------------------------------------------------------------
    761 // Global Queues
    762 void doregister( thread_desc & thrd ) {
    763         // lock      ( global_thread.lock );
    764         // push_front( global_thread.list, thrd );
    765         // unlock    ( global_thread.lock );
    766 }
    767 
    768 void unregister( thread_desc & thrd ) {
    769         // lock  ( global_thread.lock );
    770         // remove( global_thread.list, thrd );
    771         // unlock( global_thread.lock );
    772 }
    773 
    774 void doregister( cluster     & cltr ) {
    775         // lock      ( global_cluster.lock );
    776         // push_front( global_cluster.list, cltr );
    777         // unlock    ( global_cluster.lock );
    778 }
    779 
    780 void unregister( cluster     & cltr ) {
    781         // lock  ( global_cluster.lock );
    782         // remove( global_cluster.list, cltr );
    783         // unlock( global_cluster.lock );
    784 }
    785 
    786 
    787 void doregister( cluster * cltr, processor * proc ) {
    788         // lock      (cltr->proc_list_lock __cfaabi_dbg_ctx2);
    789         // push_front(cltr->procs, *proc);
    790         // unlock    (cltr->proc_list_lock);
    791 }
    792 
    793 void unregister( cluster * cltr, processor * proc ) {
    794         // lock  (cltr->proc_list_lock __cfaabi_dbg_ctx2);
    795         // remove(cltr->procs, *proc );
    796         // unlock(cltr->proc_list_lock);
    797 }
    798 
    799 //-----------------------------------------------------------------------------
    800740// Debug
    801741__cfaabi_dbg_debug_do(
     742        struct {
     743                thread_desc * tail;
     744        } __cfaabi_dbg_thread_list = { NULL };
     745
     746        void __cfaabi_dbg_thread_register( thread_desc * thrd ) {
     747                if( !__cfaabi_dbg_thread_list.tail ) {
     748                        __cfaabi_dbg_thread_list.tail = thrd;
     749                        return;
     750                }
     751                __cfaabi_dbg_thread_list.tail->dbg_next = thrd;
     752                thrd->dbg_prev = __cfaabi_dbg_thread_list.tail;
     753                __cfaabi_dbg_thread_list.tail = thrd;
     754        }
     755
     756        void __cfaabi_dbg_thread_unregister( thread_desc * thrd ) {
     757                thread_desc * prev = thrd->dbg_prev;
     758                thread_desc * next = thrd->dbg_next;
     759
     760                if( next ) { next->dbg_prev = prev; }
     761                else       {
     762                        assert( __cfaabi_dbg_thread_list.tail == thrd );
     763                        __cfaabi_dbg_thread_list.tail = prev;
     764                }
     765
     766                if( prev ) { prev->dbg_next = next; }
     767
     768                thrd->dbg_prev = NULL;
     769                thrd->dbg_next = NULL;
     770        }
     771
    802772        void __cfaabi_dbg_record(__spinlock_t & this, const char * prev_name) {
    803773                this.prev_name = prev_name;
Note: See TracChangeset for help on using the changeset viewer.