Ignore:
Timestamp:
Feb 20, 2018, 5:32:17 PM (6 years ago)
Author:
alain
Message:

Fix a bad bug in scheduler...

File:
1 edited

Legend:

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

    r433 r435  
    2424#include <hal_types.h>
    2525#include <hal_uspace.h>
     26#include <hal_irqmask.h>
    2627#include <core.h>
    2728#include <thread.h>
     
    4243    int         child_state;
    4344    thread_t  * child_thread;
     45    reg_t       save_sr;
    4446
    4547    thread_t  * this    = CURRENT_THREAD;
     
    6163        if( error )
    6264        {
    63         printk("\n[ERROR] in %s : status buffer unmapped for thread %x in process %x\n",
    64         __FUNCTION__ , this->trdid , process->pid );
     65
     66#if CONFIG_DEBUG_SYSCALLS_ERROR
     67printk("\n[ERROR] in %s : status buffer unmapped for thread %x in process %x\n",
     68__FUNCTION__ , this->trdid , process->pid );
     69#endif
    6570        this->errno = EFAULT;
    6671                return -1;
     
    8590    while( 1 )
    8691    {
     92        // enable IRQS
     93        hal_enable_irq( &save_sr );
     94 
    8795        // get lock protecting children list
    8896        remote_spinlock_lock( children_lock_xp );
     
    101109            // test if child process is terminated,
    102110            // but termination not yet reported to parent process
    103             if( ((child_state & PROCESS_FLAG_EXIT)   ||
    104                  (child_state & PROCESS_FLAG_KILL)   ||
    105                  (child_state & PROCESS_FLAG_BLOCK)) &&
    106                  ((child_state & PROCESS_FLAG_WAIT) == 0) )
     111            if( ((child_state & PROCESS_TERM_EXIT)  ||
     112                 (child_state & PROCESS_TERM_KILL)  ||
     113                 (child_state & PROCESS_TERM_STOP)) &&
     114                 ((child_state & PROCESS_TERM_WAIT) == 0) )
    107115            {
    108116                // get pointer on main thread and PID from child owner process
     
    112120                // set the PROCESS_FLAG_WAIT in owner child descriptor
    113121                hal_remote_atomic_or( XPTR( child_cxy , &child_ptr->term_state ),
    114                                       PROCESS_FLAG_WAIT );
     122                                      PROCESS_TERM_WAIT );
    115123
    116124                // set the THREAD_FLAG_REQ_DELETE in child main thread
     
    118126                                            THREAD_FLAG_REQ_DELETE );
    119127
     128                // release lock protecting children list
     129                remote_spinlock_unlock( children_lock_xp );
     130
    120131#if CONFIG_DEBUG_SYS_WAIT
    121132tm_end = hal_get_cycles();
    122133if( CONFIG_DEBUG_SYS_WAIT < tm_end )
    123 printk("\n[DBG] %s : thread %x exit / process %x / cycle %d\n",
    124 __FUNCTION__, this, process->pid, (uint32_t)tm_end );
     134printk("\n[DBG] %s : thread %x exit / parent %x / child %x / cycle %d\n",
     135__FUNCTION__, this, process->pid, child_pid, (uint32_t)tm_end );
    125136#endif
    126 
    127137                 // return relevant info to calling parent process
    128138                 hal_copy_to_uspace( status , &child_state , sizeof(int) );
     
    131141        }
    132142       
    133         // release lock
     143        // release lock protecting children list
    134144        remote_spinlock_unlock( children_lock_xp );
    135145
    136146        // deschedule without blocking
    137147        sched_yield( "parent wait children termination" );
    138     }
     148
     149    }  // end while
    139150
    140151    // never executed
Note: See TracChangeset for help on using the changeset viewer.