Ignore:
Timestamp:
Jun 19, 2018, 5:12:57 PM (6 years ago)
Author:
alain
Message:

miscelaneous...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_exit.c

    r445 r446  
    3636int sys_exit( uint32_t status )
    3737{
    38     reg_t       save_sr;       // required to enable IRQs
     38    reg_t       save_sr;           // required to enable IRQs
     39
     40    xptr_t      owner_xp;          // extended pointer on owner process
     41    cxy_t       owner_cxy;         // owner process cluster
     42    process_t * owner_ptr;         // local pointer on owner process
     43    thread_t  * main_ptr;          // local pointer on process main thread
     44    xptr_t      parent_xp;         // extended pointer on parent process
     45    cxy_t       parent_cxy;        // parent process cluster
     46    process_t * parent_ptr;        // local pointer on parent process
     47    xptr_t      children_lock_xp;  // extended pointer on children locki
     48    thread_t  * parent_main_ptr;   // local pointer on parent main thread
     49    xptr_t      parent_main_xp;    // extended pointer on parent main thread
     50    uint32_t    term_state;        // termination status for owner process
    3951
    4052    thread_t  * this    = CURRENT_THREAD;
     
    5264
    5365    // get owner process descriptor pointers
    54     xptr_t      owner_xp  = process->owner_xp;
    55     cxy_t       owner_cxy = GET_CXY( owner_xp );
    56     process_t * owner_ptr = GET_PTR( owner_xp );
     66    owner_xp  = process->owner_xp;
     67    owner_cxy = GET_CXY( owner_xp );
     68    owner_ptr = GET_PTR( owner_xp );
    5769
    58     // get pointers on the process main thread
    59     thread_t * main    = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) );
    60 
    61     // enable IRQs
    62     hal_enable_irq( &save_sr );
    63 
    64     // mark for delete all process threads in all clusters,
    65     // but the main thread and this calling thread
    66     process_sigaction( pid , DELETE_ALL_THREADS );
    67 
    68     // disable IRQs
    69     hal_restore_irq( save_sr );
    70 
    71 #if( DEBUG_SYS_EXIT & 1)
    72 if( tm_start > DEBUG_SYS_EXIT )
    73 printk("\n[DBG] %s : thread %x deleted threads / process %x\n",
    74 __FUNCTION__ , this, pid );
     70#if (DEBUG_SYS_EXIT & 1)
     71if( DEBUG_SYS_EXIT < tm_start )
     72printk("\n[DBG] %s : thread %x get owner process %x in cluster %x\n",
     73__FUNCTION__ , this, owner_ptr, owner_cxy );
    7574#endif
    7675
    77     // mark for delete this calling thread when it is not the main
    78     if( (owner_cxy != local_cxy) || (main != this) )
    79     {
     76    // get pointer on the process main thread
     77    main_ptr  = hal_remote_lpt( XPTR( owner_cxy , &owner_ptr->th_tbl[0] ) );
    8078
    81 #if( DEBUG_SYS_EXIT & 1)
    82 if( tm_start > DEBUG_SYS_EXIT )
    83 printk("\n[DBG] %s : calling thread %x marked iself for delete / process %x\n",
    84 __FUNCTION__ , this, pid );
     79    // get parent process descriptor pointers
     80    parent_xp  = process->parent_xp;
     81    parent_cxy = GET_CXY( parent_xp );
     82    parent_ptr = GET_PTR( parent_xp );
     83
     84#if (DEBUG_SYS_EXIT & 1)
     85if( DEBUG_SYS_EXIT < tm_start )
     86printk("\n[DBG] %s : thread %x get parent process %x in cluster %x\n",
     87__FUNCTION__ , this, parent_ptr, parent_cxy );
    8588#endif
    86         thread_delete( XPTR( local_cxy , this ) , pid , true );
    87     }
     89
     90    // get extended pointer on lock protecting children list in parent process
     91    children_lock_xp = XPTR( parent_cxy , &parent_ptr->children_lock );
     92
     93    // get pointers on the parent process main thread
     94    parent_main_ptr = hal_remote_lpt( XPTR( parent_cxy , &parent_ptr->th_tbl[0] ) );
     95    parent_main_xp  = XPTR( parent_cxy , parent_main_ptr );
    8896
    8997    // remove process from TXT list
     
    96104#endif
    97105
    98     // block the main thread
    99     thread_block( XPTR( owner_cxy , main ) , THREAD_BLOCKED_GLOBAL );
     106    // mark for delete all process threads in all clusters,
     107    // but the main thread and this calling thread
     108    hal_enable_irq( &save_sr );
     109    process_sigaction( pid , DELETE_ALL_THREADS );
     110    hal_restore_irq( save_sr );
     111
     112#if( DEBUG_SYS_EXIT & 1)
     113if( tm_start > DEBUG_SYS_EXIT )
     114printk("\n[DBG] %s : thread %x deleted threads for process %x\n",
     115__FUNCTION__ , this, pid );
     116#endif
     117
     118    // mark for delete this calling thread when it is not the main
     119    if( (owner_cxy != local_cxy) || (main_ptr != this) )
     120    {
     121
     122#if( DEBUG_SYS_EXIT & 1)
     123if( tm_start > DEBUG_SYS_EXIT )
     124printk("\n[DBG] %s : calling thread %x marked iself for delete in process %x\n",
     125__FUNCTION__ , this, pid );
     126#endif
     127        thread_delete( XPTR( local_cxy , this ) , pid , true );
     128    }
     129
     130    // block this main thread
     131    thread_block( XPTR( owner_cxy , main_ptr ) , THREAD_BLOCKED_GLOBAL );
    100132
    101133#if( DEBUG_SYS_EXIT & 1)
     
    107139    // atomically update owner process descriptor term_state to ask
    108140    // the parent process sys_wait() function to delete the main thread
    109     hal_remote_atomic_or( XPTR( owner_cxy , &process->term_state ) ,
    110                           PROCESS_TERM_EXIT | (status & 0xFF) );
     141    term_state = (status & 0xFF) | PROCESS_TERM_EXIT;
     142    hal_remote_atomic_or( XPTR( owner_cxy , &owner_ptr->term_state ) , term_state );
    111143
    112144#if( DEBUG_SYS_EXIT & 1)
    113145if( tm_start > DEBUG_SYS_EXIT )
    114 printk("\n[DBG] %s : thread %x set exit status in process %x term_state\n",
    115 __FUNCTION__ , this, pid );
     146printk("\n[DBG] %s : thread %x set exit status in process %x / term_state %x\n",
     147__FUNCTION__ , this, pid, term_state );
     148#endif
     149
     150    // take the children lock and unblock the parent process main thread
     151    remote_spinlock_lock( children_lock_xp );
     152    thread_unblock( parent_main_xp , THREAD_BLOCKED_WAIT );
     153    remote_spinlock_unlock( children_lock_xp );
     154
     155#if( DEBUG_SYS_EXIT & 1)
     156if( tm_start > DEBUG_SYS_EXIT )
     157printk("\n[DBG] %s : thread %x in cluster %x unblock parent main thread %x in cluster %x\n",
     158__FUNCTION__ , this, local_cxy, parent_main_ptr, parent_cxy );
    116159#endif
    117160
Note: See TracChangeset for help on using the changeset viewer.