Ignore:
Timestamp:
Nov 14, 2019, 11:50:09 AM (3 years ago)
Author:
alain
Message:

1) Improve the VMM MMAP allocator: implement the "buddy" algorithm
to allocate only aligned blocks.
2) fix a bug in the pthread_join() / pthread_exit() mmechanism.

File:
1 edited

Legend:

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

    r635 r651  
    3333#include <syscalls.h>
    3434
    35 ////////////////////////////////////////
    36 int sys_thread_exit( void * exit_value )
     35/////////////////////////////////////////
     36int sys_thread_exit( void * exit_status )
    3737{
     38    error_t     error;
     39    vseg_t    * vseg;
     40
    3841        thread_t  * this      = CURRENT_THREAD;
    3942    trdid_t     trdid     = this->trdid;
    4043    process_t * process   = this->process;
    4144    pid_t       pid       = process->pid;
     45   
     46    // check exit_value pointer in user space if required
     47    if( exit_status != NULL )
     48    {
     49        error = vmm_get_vseg( process , (intptr_t)exit_status  , &vseg );
    4250
    43     // check exit_value argument
    44     if( exit_value != NULL )
    45     {
     51        if( error )
     52            {
    4653
    4754#if DEBUG_SYSCALLS_ERROR
    48 printk("\n[ERROR] in %s : thread[%x,%x] / exit_value argument %x must be NULL\n",
    49 __FUNCTION__ , pid, trdid , exit_value );
     55printk("\n[ERROR] in %s : exit_status buffer %x unmapped / thread[%x,%x]\n",
     56__FUNCTION__, (intptr_t)exit_status, process->pid, this->trdid );
    5057#endif
    51         this->errno = EINVAL;
    52         return -1;
     58            this->errno = EINVAL;
     59                return -1;
     60        }
     61    }
     62
     63        // check busylocks
     64    uint32_t count = this->busylocks;
     65        if( count )
     66        {
     67
     68#if DEBUG_SYSCALLS_ERROR
     69printk("\n[ERROR] in %s : busylocks count = %d  / thread[%x,%x]\n",
     70__FUNCTION__ , count, process->pid, this->trdid );
     71#endif
     72            this->errno = EINVAL;
     73                return -1;
    5374    }
    5475
    5576    // If calling thread is the main thread, the process must be deleted.
    56     // => delete all process threads and synchronise with parent process.
    57     // If calling thread is not the main thread, it must be deleted.
    58     // => block the thread and mark it for delete.
    59     if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) )
     77    // => delete all process threads and synchronize with parent process.
     78    // If calling thread is not the main thread, only this thread must be deleted.
     79    // => register exit_status in thread descriptor, block the thread,
     80    //    mark it for delete, and synchronize with joining thread.
     81
     82    if( (CXY_FROM_PID( pid ) == local_cxy) && (LTID_FROM_TRDID(trdid) == 0) )  // main
    6083    {
    6184
     
    6992        sys_exit( 0 );
    7093    }
    71     else
     94    else                                                             // not the main
    7295    {
    7396
     
    78101__FUNCTION__ , pid , trdid , (uint32_t)tm_start );
    79102#endif
     103        // register exit_status in thread descriptor
     104        this->exit_status = exit_status;
     105
    80106        // block calling thread and mark it for delete,
    81         thread_delete( XPTR( local_cxy , this ) , pid , false );
     107        thread_delete( XPTR( local_cxy , this ) , false );   // not forced
    82108
    83109        // deschedule
Note: See TracChangeset for help on using the changeset viewer.