Ignore:
Timestamp:
Nov 1, 2018, 12:13:45 PM (6 years ago)
Author:
alain
Message:

Introduce sys_place_fork() function.

File:
1 edited

Legend:

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

    r566 r584  
    3636int sys_thread_exit( void * exit_value )
    3737{
    38     reg_t       save_sr;    // required to enable IRQs
    39     xptr_t      owner_xp;   // extended pointer on owner process
    40  
    4138        thread_t  * this      = CURRENT_THREAD;
    4239    trdid_t     trdid     = this->trdid;
    4340    process_t * process   = this->process;
    4441    pid_t       pid       = process->pid;
    45     cxy_t       owner_cxy = CXY_FROM_PID( pid );
    4642
    4743    // check exit_value argument
     
    5753    }
    5854
    59 #if DEBUG_SYS_THREAD_EXIT
    60 uint64_t     tm_start;
    61 uint64_t     tm_end;
    62 tm_start = hal_get_cycles();
    63 if( DEBUG_SYS_THREAD_EXIT < tm_start )
    64 printk("\n[DBG] %s : thread %x in process %x enter / cycle %d\n",
    65 __FUNCTION__ , this->trdid, pid , (uint32_t)tm_start );
    66 #endif
    6755
    6856    // If calling thread is the main thread, the process must be deleted.
    69     // This require to delete all process threads and synchronise with parent process
    70     if( (local_cxy == owner_cxy) && (LTID_FROM_TRDID(trdid) == 0) )
     57    // => delete all process threads and synchronise with parent process.
     58    // If calling thread is not the main thread, it must be deleted.
     59    // => block the thread and mark it for delete.
     60    if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) )
    7161    {
    72         // get extended pointer on owner cluster
    73         owner_xp = cluster_get_owner_process_from_pid( pid );
    7462
    75         // mark for delete all threads but the main
    76         hal_enable_irq( &save_sr );
    77         process_sigaction( pid , DELETE_ALL_THREADS );
    78         hal_restore_irq( save_sr );
    79 
    80         // remove process from TXT list
    81         process_txt_detach( owner_xp );
    82 
    83         // block the main thread
    84         thread_block( XPTR( local_cxy , this ) , THREAD_BLOCKED_GLOBAL );
    85 
    86         // atomically update owner process descriptor term_state to ask
    87         // the parent process sys_wait() function to delete the main thread
    88         hal_remote_atomic_or( XPTR( local_cxy , &process->term_state ) ,
    89                               PROCESS_TERM_EXIT );
     63#if DEBUG_SYS_THREAD_EXIT
     64uint64_t     tm_start = hal_get_cycles();
     65if( DEBUG_SYS_THREAD_EXIT < tm_start )
     66printk("\n[DBG] %s : thread[%x,%x] / main => delete process / cycle %d\n",
     67__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
     68#endif
     69        // delete process
     70        sys_exit( 0 );
    9071    }
    9172    else
    9273    {
     74
     75#if DEBUG_SYS_THREAD_EXIT
     76uint64_t     tm_start = hal_get_cycles();
     77if( DEBUG_SYS_THREAD_EXIT < tm_start )
     78printk("\n[DBG] %s : thread[%x,%x] / not main => delete thread / cycle %d\n",
     79__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
     80#endif
    9381        // block calling thread and mark it for delete,
    9482        thread_delete( XPTR( local_cxy , this ) , pid , false );
     83
     84        // deschedule
     85        sched_yield( "suicide after thread_exit" );
    9586    }
    9687
    97 #if DEBUG_SYS_THREAD_EXIT
    98 tm_end = hal_get_cycles();
    99 if( DEBUG_SYS_THREAD_EXIT < tm_end )
    100 printk("\n[DBG] %s : thread %x in process %x exit / cost %d / cycle %d\n",
    101 __FUNCTION__, this->trdid, pid, (uint32_t)(tm_end - tm_start), (uint32_t)tm_end );
    102 #endif
    103 
    104     // deschedule <=> suicide, because blocked by thread_delete()
    105     sched_yield( "suicide after thread_exit" );
    106    
    10788    return 0;   // never executed but required by compiler
    10889
Note: See TracChangeset for help on using the changeset viewer.