Ignore:
Timestamp:
Oct 4, 2018, 11:16:13 PM (6 years ago)
Author:
alain
Message:

Complete restructuration of kernel spinlocks.

File:
1 edited

Legend:

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

    r492 r563  
    2727#include <hal_remote.h>
    2828#include <xlist.h>
    29 #include <remote_rwlock.h>
     29#include <remote_busylock.h>
    3030#include <string.h>
    3131#include <printk.h>
     
    3535
    3636///////////////////////////////////////////////////////////////////////////////////////////
    37 // Item type specific functions (three functions for each item type).
    38 ///////////////////////////////////////////////////////////////////////////////////////////
    39 
    40 ///////////////////////////////////////////////////////////////////////////////////////////
    41 // This functions compute the hash index from the key when item is a vfs_dentry_t.
    42 // The key is the directory entry name.
     37// Item type specific functions (four functions for each item type).
     38// Example below is for <vfs_dentry_t> where the identifier is the dentry name.
     39///////////////////////////////////////////////////////////////////////////////////////////
     40
     41///////////////////////////////////////////////////////////////////////////////////////////
     42// vfs_dentry_t
     43// This functions compute the hash index from the key, that is the directory entry name.
    4344///////////////////////////////////////////////////////////////////////////////////////////
    4445// @ key      : local pointer on name.
     
    5758
    5859///////////////////////////////////////////////////////////////////////////////////////////
     60// vfs_dentry_t
    5961// This functions returns the extended pointer on the item, from the extended pointer
    60 // on xlist contained in the item, when the item is a vfs_entry_t.
     62// on xlist contained in the item.
    6163///////////////////////////////////////////////////////////////////////////////////////////
    6264// @ xlist_xp      : extended pointer on embedded xlist entry.
     
    6971
    7072////////////////////////////////////////////////////////////////////////////////////////////
    71 // This function compare the identifier of an item to a given <key>. For a vfs_entry_t,
     73// vfs_dentry_t
     74// This function compares the identifier of an item to a given <key>.
    7275// it returns true when the directory name matches the name pointed by the <key> argument.
    7376////////////////////////////////////////////////////////////////////////////////////////////
     
    8386    // get dentry cluster and local pointer
    8487    cxy_t          dentry_cxy = GET_CXY( item_xp );
    85     vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );
     88    vfs_dentry_t * dentry_ptr = GET_PTR( item_xp );
    8689
    8790    // make a local copy of directory entry name
     
    9396
    9497////////////////////////////////////////////////////////////////////////////////////////////
    95 // This function print the item key, that is the name for a vfs_entry_t,
     98// vfs_dentry_t
     99// This function print the item key, that is the name for a vfs_dentry_t.
    96100////////////////////////////////////////////////////////////////////////////////////////////
    97101// @ item_xp   : extended pointer on item.
     
    103107    // get dentry cluster and local pointer
    104108    cxy_t          dentry_cxy = GET_CXY( item_xp );
    105     vfs_dentry_t * dentry_ptr = (vfs_dentry_t *)GET_PTR( item_xp );
     109    vfs_dentry_t * dentry_ptr = GET_PTR( item_xp );
    106110   
    107111    // make a local copy of directory entry name
     
    124128
    125129    // initialize readlock
    126     remote_rwlock_init( XPTR( local_cxy , &xhtab->lock) );
     130    remote_busylock_init( XPTR( local_cxy , &xhtab->lock), LOCK_XHTAB_STATE );
    127131
    128132    xhtab->items            = 0;
     
    163167    // get hash table cluster and local pointer
    164168    xhtab_cxy = GET_CXY( xhtab_xp );
    165     xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     169    xhtab_ptr = GET_PTR( xhtab_xp );
    166170
    167171    // get pointer on "item_from_xlist" function
     
    198202    index_from_key_t * index_from_key;     // function pointer
    199203   
    200     // get xhtab cluster and local pointer
    201     xhtab_cxy = GET_CXY( xhtab_xp );
    202     xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     204#if DEBUG_XHTAB
     205printk("\n[DBG] %s : enter / %s\n", __FUNCTION__, key );
     206#endif
     207
     208    // get xhtab cluster and local pointer
     209    xhtab_cxy = GET_CXY( xhtab_xp );
     210    xhtab_ptr = GET_PTR( xhtab_xp );
    203211
    204212    // get pointer on "index_from_key" function
     
    209217
    210218    // take the lock protecting hash table
    211     remote_rwlock_wr_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     219    remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    212220
    213221    // search a matching item
     
    217225    {
    218226        // release the lock protecting hash table
    219         remote_rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     227        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    220228
    221229        return EINVAL;
     
    230238
    231239        // release the lock protecting hash table
    232         remote_rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     240        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     241   
     242#if DEBUG_XHTAB
     243printk("\n[DBG] %s : success / %s\n", __FUNCTION__, key );
     244#endif
    233245
    234246        return 0;
     
    249261    // get xhtab cluster and local pointer
    250262    xhtab_cxy = GET_CXY( xhtab_xp );
    251     xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     263    xhtab_ptr = GET_PTR( xhtab_xp );
    252264
    253265    // get pointer on "index_from_key" function
     
    258270
    259271    // take the lock protecting hash table
    260     remote_rwlock_wr_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     272    remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    261273
    262274    // get extended pointer on item to remove
     
    266278    {
    267279        // release the lock protecting hash table
    268         remote_rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     280        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    269281
    270282        return EINVAL;
     
    279291
    280292        // release the lock protecting hash table
    281         remote_rwlock_wr_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     293        remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    282294
    283295        return 0;
     
    297309    // get xhtab cluster and local pointer
    298310    xhtab_cxy = GET_CXY( xhtab_xp );
    299     xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     311    xhtab_ptr = GET_PTR( xhtab_xp );
    300312
    301313    // get pointer on "index_from_key" function
     
    304316    // compute index from key
    305317        index = index_from_key( key );
     318   
     319#if DEBUG_XHTAB
     320printk("\n[DBG] %s : enter / %s\n", __FUNCTION__, key );
     321#endif
    306322
    307323    // take the lock protecting hash table
    308     remote_rwlock_rd_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     324    remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     325   
     326#if DEBUG_XHTAB
     327printk("\n[DBG] %s : after lock acquire / %s\n", __FUNCTION__, key );
     328#endif
    309329
    310330    // scan sub-list
    311331    item_xp = xhtab_scan( xhtab_xp , index , key );
    312332
     333#if DEBUG_XHTAB
     334printk("\n[DBG] %s : after xhtab scan / %s\n", __FUNCTION__, key );
     335#endif
     336
    313337    // release the lock protecting hash table
    314     remote_rwlock_rd_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     338    remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     339
     340#if DEBUG_XHTAB
     341printk("\n[DBG] %s : after lock release / %s\n", __FUNCTION__, key );
     342#endif
    315343
    316344    return item_xp;
     
    318346}  // end xhtab_lookup()
    319347
    320 ///////////////////////////////////////
    321 void xhtab_read_lock( xptr_t xhtab_xp )
     348//////////////////////////////////
     349void xhtab_lock( xptr_t xhtab_xp )
    322350{
    323351    // get xhtab cluster and local pointer
    324352    cxy_t     xhtab_cxy = GET_CXY( xhtab_xp );
    325     xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     353    xhtab_t * xhtab_ptr = GET_PTR( xhtab_xp );
    326354
    327355    // take the lock protecting hash table
    328     remote_rwlock_rd_lock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     356    remote_busylock_acquire( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    329357}
    330358
    331 /////////////////////////////////////////
    332 void xhtab_read_unlock( xptr_t xhtab_xp )
     359////////////////////////////////////
     360void xhtab_unlock( xptr_t xhtab_xp )
    333361{
    334362    // get xhtab cluster and local pointer
    335363    cxy_t     xhtab_cxy = GET_CXY( xhtab_xp );
    336     xhtab_t * xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     364    xhtab_t * xhtab_ptr = GET_PTR( xhtab_xp );
    337365
    338366    // release the lock protecting hash table
    339     remote_rwlock_rd_unlock( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
     367    remote_busylock_release( XPTR( xhtab_cxy , &xhtab_ptr->lock ) );
    340368}
    341369
     
    353381    // get xhtab cluster and local pointer
    354382    xhtab_cxy = GET_CXY( xhtab_xp );
    355     xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     383    xhtab_ptr = GET_PTR( xhtab_xp );
    356384
    357385    // get pointer on "item_from_xlist" function
     
    373401
    374402            // register item in hash table header
    375             hal_remote_sw ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index );
    376             hal_remote_swd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp );
     403            hal_remote_s32 ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index );
     404            hal_remote_s64( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp );
    377405
    378406            return item_xp;
     
    401429    // get xhtab cluster and local pointer
    402430    xhtab_cxy = GET_CXY( xhtab_xp );
    403     xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     431    xhtab_ptr = GET_PTR( xhtab_xp );
    404432
    405433    // get current item pointers
    406     current_index    = hal_remote_lw ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) );
    407     current_xlist_xp = hal_remote_lwd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) );
     434    current_index    = hal_remote_l32 ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) );
     435    current_xlist_xp = hal_remote_l64( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) );
    408436
    409437    // get pointer on "item_from_xlist" function
     
    426454
    427455            // register item in hash table header
    428             hal_remote_sw ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index );
    429             hal_remote_swd( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp );
     456            hal_remote_s32 ( XPTR( xhtab_cxy , &xhtab_ptr->current_index ) , index );
     457            hal_remote_s64( XPTR( xhtab_cxy , &xhtab_ptr->current_xlist_xp ) , xlist_xp );
    430458
    431459            return item_xp;
     
    452480    // get xhtab cluster and local pointer
    453481    xhtab_cxy = GET_CXY( xhtab_xp );
    454     xhtab_ptr = (xhtab_t *)GET_PTR( xhtab_xp );
     482    xhtab_ptr = GET_PTR( xhtab_xp );
    455483
    456484    // get pointer on "item_from_xlist" function
Note: See TracChangeset for help on using the changeset viewer.