wiki:library_locks

Version 3 (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

The lock being shared by several tasks, is defined as a global variable in the application code. It is possible to control precisely the placement of a specific lock by defining a specific vseg in the application mapping.

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. It can be used for lock initialization.