Ignore:
Timestamp:
Aug 2, 2018, 11:47:13 AM (2 years ago)
Author:
alain
Message:

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/libk/remote_sem.c

    r436 r457  
    2222 */
    2323
    24 #include <hal_types.h>
     24#include <hal_kernel_types.h>
    2525#include <hal_remote.h>
    2626#include <thread.h>
     
    7575
    7676///////////////////////////////////////////
    77 error_t remote_sem_create( intptr_t  vaddr,
    78                            uint32_t  value )
    79 {
     77error_t remote_sem_create( intptr_t   vaddr,
     78                           uint32_t   value,
     79                           xptr_t     sem_xp_xp )
     80{
     81    remote_sem_t * sem_ptr;
    8082    xptr_t         sem_xp;
    81     remote_sem_t * sem_ptr;
    8283
    8384    // get pointer on local process descriptor
     
    103104    {
    104105        rpc_kcm_alloc_client( ref_cxy , KMEM_SEM , &sem_xp );
    105         sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
    106     }
    107 
    108     if( sem_xp == XPTR_NULL ) return ENOMEM;
     106        sem_ptr = GET_PTR( sem_xp );
     107    }
     108
     109    if( sem_xp == XPTR_NULL ) return -1;
    109110
    110111    // initialise semaphore
    111112    hal_remote_sw ( XPTR( ref_cxy , &sem_ptr->count ) , value );
    112113        hal_remote_spt( XPTR( ref_cxy , &sem_ptr->ident ) , (void *)vaddr );
    113 
    114114    remote_spinlock_init( XPTR( ref_cxy , &sem_ptr->lock ) );
    115115        xlist_root_init( XPTR( ref_cxy , &sem_ptr->root ) );
     
    119119    xptr_t root_xp = XPTR( ref_cxy , &ref_ptr->sem_root );
    120120    xptr_t xp_list = XPTR( ref_cxy , &sem_ptr->list );
    121 
    122121    remote_spinlock_lock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    123122    xlist_add_first( root_xp , xp_list );
    124123    remote_spinlock_unlock( XPTR( ref_cxy , &ref_ptr->sync_lock ) );
    125124
     125    // write extended pointer on semaphore in calling thread buffer
     126    hal_remote_swd( sem_xp_xp , sem_xp );
     127
    126128    return 0;
    127129
    128 }  // en remote_sem_init()
     130}  // en remote_sem_create()
    129131 
    130132////////////////////////////////////////
     
    139141    // get reference process cluster and local pointer
    140142    cxy_t       ref_cxy = GET_CXY( ref_xp );
    141     process_t * ref_ptr = (process_t *)GET_PTR( ref_xp );
     143    process_t * ref_ptr = GET_PTR( ref_xp );
    142144
    143145    // get semaphore cluster and local pointer
     
    148150    remote_spinlock_lock( XPTR( sem_cxy , &sem_ptr->lock ) );
    149151 
    150     // get remote pointer on waiting queue
    151     xptr_t root_xp = (xptr_t)hal_remote_lwd( XPTR( sem_cxy , &sem_ptr->root ) );
     152    // get remote pointer on waiting queue root
     153    xptr_t root_xp = XPTR( sem_cxy , &sem_ptr->root );
    152154 
    153155    if( !xlist_is_empty( root_xp ) )   // user error
     
    184186}  // end remote_sem_destroy()
    185187
    186 //////////////////////////////////
     188/////////////////////////////////////
    187189void remote_sem_wait( xptr_t sem_xp )
    188190{
    189191    // get semaphore cluster and local pointer
    190192    cxy_t          sem_cxy = GET_CXY( sem_xp );
    191     remote_sem_t * sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
     193    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
    192194
    193195    // get lock protecting semaphore     
     
    210212
    211213        // register thread in waiting queue
    212         xptr_t root_xp   = (xptr_t)hal_remote_lwd( XPTR( sem_cxy , &sem_ptr->root ) );
    213         xptr_t thread_xp = XPTR( local_cxy , this );
    214                 xlist_add_last( root_xp , thread_xp );
     214        xptr_t root_xp = XPTR( sem_cxy   , &sem_ptr->root );
     215        xptr_t list_xp = XPTR( local_cxy , &this->wait_list );
     216                xlist_add_last( root_xp , list_xp );
    215217
    216218        // release lock
     
    228230    // get semaphore cluster and local pointer
    229231    cxy_t          sem_cxy = GET_CXY( sem_xp );
    230     remote_sem_t * sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
     232    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
    231233
    232234    // get lock protecting semaphore
    233235        remote_spinlock_lock( XPTR( sem_cxy , &sem_ptr->lock ) );
    234236 
     237    // get semaphore current value
     238    uint32_t count = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
     239
    235240    // get remote pointer on waiting queue root
    236     xptr_t root_xp = (xptr_t)hal_remote_lwd( XPTR( sem_cxy , &sem_ptr->root ) );
     241    xptr_t root_xp = XPTR( sem_cxy , &sem_ptr->root );
    237242 
    238243        if( xlist_is_empty( root_xp ) )   // no waiting thread
    239244    {
    240         // get semaphore current value
    241         uint32_t count = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
    242 
    243245        // increment semaphore value
    244246        hal_remote_sw( XPTR( sem_cxy , &sem_ptr->count ) , count + 1 );
     
    251253        // get thread cluster and local poiner
    252254        cxy_t      thread_cxy = GET_CXY( thread_xp );
    253         thread_t * thread_ptr = (thread_t *)GET_PTR( thread_xp );
    254 
    255         // remove the thread from the waiting queue, and unblock
     255        thread_t * thread_ptr = GET_PTR( thread_xp );
     256
     257        // remove this thread from the waiting queue, and unblock it
    256258        xlist_unlink( XPTR( thread_cxy , &thread_ptr->wait_list ) );
    257259                thread_unblock( thread_xp , THREAD_BLOCKED_SEM );
     
    270272    // get semaphore cluster and local pointer
    271273    cxy_t          sem_cxy = GET_CXY( sem_xp );
    272     remote_sem_t * sem_ptr = (remote_sem_t *)GET_PTR( sem_xp );
     274    remote_sem_t * sem_ptr = GET_PTR( sem_xp );
    273275
    274276    *data = hal_remote_lw( XPTR( sem_cxy , &sem_ptr->count ) );
Note: See TracChangeset for help on using the changeset viewer.