Ignore:
Timestamp:
Jul 22, 2012, 12:06:11 PM (12 years ago)
Author:
karaoui
Message:

updating libs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/libs/spin_lock.c

    r165 r178  
    1010// It is a simple binary lock, without waiting queue.
    1111//
    12 // The lock_acquire() and lock_release() functions do not require a system call.
    13 // The barrier itself must have been allocated in a non cacheable segment,
    14 // if the platform does not provide hardwate cache coherence.
     12// The lock_acquire(), lock_try_acquire() and lock_release() functions do
     13// not require a system call.
    1514//
    1615// ALL locks must be defined in the mapping_info data structure,
    1716// to be initialised by the GIET in the boot phase.
    1817// The vobj_get_vbase() system call (defined in stdio.c and stdio.h files)
    19 // can be used to get the virtual base address of the lock fro it's name.
     18// can be used to get the virtual base address of the lock from it's name.
    2019///////////////////////////////////////////////////////////////////////////////////
    2120
     
    6564}
    6665
     66//////////////////////////////////////////////////////////////////////////////
     67// lock_try_acquire()
     68//////////////////////////////////////////////////////////////////////////////
     69int lock_try_acquire( giet_lock_t* lock )
     70{
     71        register int ret = 0;   
     72    register unsigned int*      plock = &lock->value;
     73
     74        asm volatile ("ll   $2,    0(%1)                    \n" // $2 <= _locks_lock
     75                  "bnez $2,    _lock_done           \n" // exitif busy
     76                  "li   $3,    1                            \n" // prepare argument for sc 
     77                  "sc   $3,    0(%1)                \n" // try to set _locks_busy
     78                  "xori %0, $3, 1                   \n" // ret = !$3
     79                  "_lock_done:                          \n"
     80                  :"=r"(ret)
     81                  :"r"(plock)
     82                  :"$2","$3");
     83    return ret;
     84}
Note: See TracChangeset for help on using the changeset viewer.