Ignore:
Timestamp:
Jan 4, 2018, 10:05:47 AM (6 years ago)
Author:
alain
Message:

Improve sys_exec.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/kern/thread.c

    r409 r416  
    696696}  // thread_child_parent_unlink()
    697697
    698 /////////////////////////////////////////////////
    699 inline void thread_set_signal( thread_t * thread,
    700                                uint32_t * sig_rsp_count )
     698//////////////////////////////////////////////////
     699inline void thread_set_req_ack( thread_t * target,
     700                                uint32_t * rsp_count )
    701701{
    702702    reg_t    save_sr;   // for critical section
    703703
    704     // get pointer on thread thread scheduler
    705     scheduler_t * thread_sched = &thread->core->scheduler;
    706 
    707     // wait scheduler ready to handle a new signal
    708     while( thread_sched->sig_pending ) asm volatile( "nop" );
     704    // get pointer on target thread scheduler
     705    scheduler_t * sched = &target->core->scheduler;
     706
     707    // wait scheduler ready to handle a new request
     708    while( sched->req_ack_pending ) asm volatile( "nop" );
    709709   
    710710    // enter critical section
    711711    hal_disable_irq( &save_sr );
    712712     
    713     // set signal in thread scheduler
    714     thread_sched->sig_pending = true;
    715 
    716     // set signal in thread thread "flags"
    717     hal_atomic_or( &thread->flags , THREAD_FLAG_SIGNAL );
    718 
    719     // set pointer on responses counter in thread thread
    720     thread->sig_rsp_count = sig_rsp_count;
     713    // set request in target thread scheduler
     714    sched->req_ack_pending = true;
     715
     716    // set ack request in target thread "flags"
     717    hal_atomic_or( &target->flags , THREAD_FLAG_REQ_ACK );
     718
     719    // set pointer on responses counter in target thread
     720    target->ack_rsp_count = rsp_count;
    721721   
    722722    // exit critical section
     
    725725    hal_fence();
    726726
    727 }  // thread_set_signal()
    728 
    729 ////////////////////////////////////////////////////
    730 inline void thread_reset_signal( thread_t * thread )
     727}  // thread_set_req_ack()
     728
     729/////////////////////////////////////////////////////
     730inline void thread_reset_req_ack( thread_t * target )
    731731{
    732732    reg_t    save_sr;   // for critical section
    733733
    734734    // get pointer on target thread scheduler
    735     scheduler_t * sched = &thread->core->scheduler;
     735    scheduler_t * sched = &target->core->scheduler;
    736736
    737737    // check signal pending in scheduler
    738     assert( sched->sig_pending , __FUNCTION__ , "no pending signal" );
     738    assert( sched->req_ack_pending , __FUNCTION__ , "no pending signal" );
    739739   
    740740    // enter critical section
     
    742742     
    743743    // reset signal in scheduler
    744     sched->sig_pending = false;
     744    sched->req_ack_pending = false;
    745745
    746746    // reset signal in thread "flags"
    747     hal_atomic_and( &thread->flags , ~THREAD_FLAG_SIGNAL );
     747    hal_atomic_and( &target->flags , ~THREAD_FLAG_REQ_ACK );
    748748
    749749    // reset pointer on responses counter
    750     thread->sig_rsp_count = NULL;
     750    target->ack_rsp_count = NULL;
    751751   
    752752    // exit critical section
     
    755755    hal_fence();
    756756
    757 }  // thread_reset_signal()
     757}  // thread_reset_req_ack()
    758758
    759759////////////////////////////////
     
    809809void thread_kill( thread_t * target )
    810810{
    811     volatile uint32_t  sig_rsp_count = 1;     // responses counter
     811    volatile uint32_t  rsp_count = 1;     // responses counter
    812812
    813813    thread_t * killer = CURRENT_THREAD;
    814814
    815 kill_dmsg("\n[DBG] %s : killer thread %x enter for target thread %x\n",
     815thread_dmsg("\n[DBG] %s : killer thread %x enter for target thread %x\n",
    816816__FUNCTION__, local_cxy, killer->trdid , target trdid );
    817817
     
    824824    {
    825825        // set signal in target thread descriptor and in target scheduler
    826         thread_set_signal( target , (uint32_t *)(&sig_rsp_count) );
     826        thread_set_req_ack( target , (void *)(&rsp_count) );
    827827
    828828        // send an IPI to the target thread core.
     
    833833        {
    834834            // exit when response received from scheduler
    835             if( sig_rsp_count == 0 )  break;
     835            if( rsp_count == 0 )  break;
    836836
    837837            // deschedule without blocking
     
    840840    }
    841841
    842         // release FPU if required
    843         if( target->core->fpu_owner == target )  target->core->fpu_owner = NULL;
    844 
    845     // detach thread from parent if attached
    846     if( (target->flags & THREAD_FLAG_DETACHED) == 0 )
    847     thread_child_parent_unlink( target->parent , XPTR( local_cxy , target ) );
    848 
    849     // detach thread from process
    850     process_remove_thread( target );
    851 
    852     // remove thread from scheduler
    853     sched_remove_thread( target );
    854 
    855     // release memory allocated to target thread
    856     thread_destroy( target );
    857 
    858 kill_dmsg("\n[DBG] %s : killer thread %x enter for target thread %x\n",
     842        // set REQ_DELETE flag
     843        hal_atomic_or( &target->flags , THREAD_FLAG_REQ_DELETE );
     844
     845thread_dmsg("\n[DBG] %s : killer thread %x exit for target thread %x\n",
    859846__FUNCTION__, local_cxy, killer->trdid , target trdid );
    860847
Note: See TracChangeset for help on using the changeset viewer.