wiki:library_locks

Version 2 (modified by alain, 10 years ago) (diff)

--

The spin_lock library

The spin_lock.c and spin_lock.h files define a user-level spin-lock service to obtain exclusive access to a shared resource in a parallel multi-tasks application. Each lock (giet_lock_t object) occupies a complete 64 bytes cache line to avoid false sharing. If the hardware architecture supports hardware cache coherence, it is recommanded to store the lock in a cachable segment architecture

Lock placement

There is to ways to define a user-level lock, depending on the placement constraints:

  • If the lock is defined as a global variable in the application code, there is no precise control on the lock placement: the lock will be stored in the application global data vseg".
  • If the lock is defined as a specific vobj in the application mapping, it will be stored in the vseg specified in the mapping. The lock should not be declared as a global variable in the application code, and the lock virtual address can be obtained using the giet_vobj_get_vbase() system call.

Access functions

  • void lock_acquire( giet_lock_t * lock )

This blocking function uses an atomic LL/SC mechanism to take the lock, and return only when the lock has been successfully taken.

  • void lock_release( giet_lock_t * lock )

This function uses a simple SW to release the lock.