Ignore:
Timestamp:
Apr 26, 2017, 2:29:23 PM (4 years ago)
Author:
alain
Message:

Merge all FS related files in one single vfs directory.

File:
1 edited

Legend:

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

    r1 r11  
    3131#include <remote_spinlock.h>
    3232
    33 ////////////////////////////////////////
    34 void remote_spinlock_init( xptr_t lock )
     33///////////////////////////////////////////
     34void remote_spinlock_init( xptr_t lock_xp )
    3535{
    36     remote_spinlock_t * ptr = (remote_spinlock_t *)GET_PTR( lock );
    37     cxy_t               cxy = GET_CXY( lock );
     36    remote_spinlock_t * ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
     37    cxy_t               cxy = GET_CXY( lock_xp );
    3838
    3939    hal_remote_sw ( XPTR( cxy , &ptr->taken ) , 0 );
     
    4242}
    4343
    44 ///////////////////////////////////////////////
    45 uint32_t remote_spinlock_trylock( xptr_t lock )
     44/////////////////////////////////////////////////
     45error_t remote_spinlock_trylock( xptr_t lock_xp )
    4646{
    4747        uint32_t            mode;
     
    4949
    5050    // get cluster and local pointer on remote_spinlock
    51     remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );
    52     cxy_t               lock_cxy = GET_CXY( lock );
     51    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
     52    cxy_t               lock_cxy = GET_CXY( lock_xp );
    5353
    5454    // get cluster and local pointer on local thread
     
    8484}
    8585
    86 ////////////////////////////////////////
    87 void remote_spinlock_lock( xptr_t lock )
     86///////////////////////////////////////////////////
     87void remote_spinlock_lock_busy( xptr_t     lock_xp,
     88                                uint32_t * irq_state )
    8889{
    8990    bool_t              isAtomic = false;
     
    9293
    9394    // get cluster and local pointer on remote_spinlock
    94     remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );
    95     cxy_t               lock_cxy = GET_CXY( lock );
     95    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
     96    cxy_t               lock_cxy = GET_CXY( lock_xp );
     97
     98    // get cluster and local pointer on local thread
     99    cxy_t               thread_cxy = local_cxy;
     100    thread_t          * thread_ptr = CURRENT_THREAD;
     101
     102    // disable interrupts
     103        hal_disable_irq( &mode );
     104 
     105    // loop until success
     106        while( isAtomic == false )
     107        {
     108                taken = hal_remote_lw( XPTR( lock_cxy , &lock_ptr->taken ) );
     109
     110        // try to take the lock if not already taken
     111                if( taken == 0 )
     112                {
     113                    isAtomic = hal_remote_atomic_cas( XPTR( lock_cxy , &lock_ptr->taken ) , 0 , 1 );
     114        }
     115        }
     116
     117    // register lock in thread
     118        thread_ptr->remote_locks++;
     119
     120    hal_remote_swd( XPTR( lock_cxy , &lock_ptr->owner ) ,
     121                    (uint64_t)XPTR( thread_cxy , thread_ptr) );
     122
     123    xlist_add_first( XPTR( thread_cxy , &thread_ptr->xlocks_root ) ,
     124                     XPTR( lock_cxy , &lock_ptr->list ) );
     125
     126    // irq_state must be restored when lock is released
     127    *irq_state = mode;
     128
     129}  // end remote_spinlock_lock_busy()
     130
     131////////////////////////////////////////////////////
     132void remote_spinlock_unlock_busy( xptr_t    lock_xp,
     133                                  uint32_t  irq_state )
     134{
     135    // get cluster and local pointer on remote_spinlock
     136    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
     137    cxy_t               lock_cxy = GET_CXY( lock_xp );
     138
     139    // get pointer on local thread
     140    thread_t          * thread_ptr = CURRENT_THREAD;
     141
     142        hal_remote_swd( XPTR( lock_cxy , &lock_ptr->owner ) , XPTR_NULL );
     143
     144        hal_remote_sw ( XPTR( lock_cxy , &lock_ptr->taken ) , 0 );
     145
     146        thread_ptr->remote_locks--;
     147
     148    xlist_unlink( XPTR( lock_cxy , &lock_ptr->list ) );
     149
     150    hal_restore_irq( irq_state );
     151}
     152
     153///////////////////////////////////////////
     154void remote_spinlock_lock( xptr_t lock_xp )
     155{
     156    bool_t              isAtomic = false;
     157        uint32_t            mode;
     158    volatile uint32_t   taken;
     159
     160    // get cluster and local pointer on remote_spinlock
     161    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
     162    cxy_t               lock_cxy = GET_CXY( lock_xp );
    96163
    97164    // get cluster and local pointer on local thread
     
    133200}
    134201
    135 //////////////////////////////////////////
    136 void remote_spinlock_unlock( xptr_t lock )
    137 {
    138     // get cluster and local pointer on remote_spinlock
    139     remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock );
    140     cxy_t               lock_cxy = GET_CXY( lock );
     202/////////////////////////////////////////////
     203void remote_spinlock_unlock( xptr_t lock_xp )
     204{
     205    // get cluster and local pointer on remote_spinlock
     206    remote_spinlock_t * lock_ptr = (remote_spinlock_t *)GET_PTR( lock_xp );
     207    cxy_t               lock_cxy = GET_CXY( lock_xp );
    141208
    142209    // get pointer on local thread
Note: See TracChangeset for help on using the changeset viewer.