| 1 | = The spin_lock library = |
| 2 | |
| 3 | The [source:soft/giet_vm/giet_libs/spin_lock.c spin_lock.c] and [source:soft/giet_vm/giet_libs/spin_lock.h spin_lock.h] |
| 4 | files define a user-level spin-lock service to obtain exclusive access to a shared resource in a parallel multi-tasks application. |
| 5 | Each lock (giet_lock_t object) occupies a complete 64 bytes cache line to avoid false sharing. |
| 6 | If the hardware architecture supports hardware cache coherence, it is recommanded to store the lock in a cachable segment architecture |
| 7 | |
| 8 | == Lock declaration == |
| 9 | |
| 10 | There is to ways to define a user-level lock, depending on the placement constraints: |
| 11 | |
| 12 | * 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". |
| 13 | |
| 14 | * 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. |
| 15 | |
| 16 | == Access functions == |
| 17 | |
| 18 | * '''void lock_acquire( giet_lock_t * lock )''' |
| 19 | This blocking function uses an atomic LL/SC mechanism to take the lock, and return only when the lock has been successfully taken. |
| 20 | |
| 21 | * '''void lock_release( giet_lock_t * lock )''' |
| 22 | This function uses a simple SW to release the lock. |