[455] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : locks.h |
---|
| 3 | // Date : 01/12/2014 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // The locks.c and locks.h files are part of the GIET-VM nano-kernel. |
---|
| 8 | // They define both atomic increment operations and locks. |
---|
| 9 | // The locks used gy the GIET_VM are spin-locks with a waiting queue. |
---|
| 10 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 11 | |
---|
| 12 | #ifndef GIET_LOCKS_H |
---|
| 13 | #define GIET_LOCKS_H |
---|
| 14 | |
---|
| 15 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 16 | // This structure implements a spin-lock with waiting file. |
---|
| 17 | // There is at most one lock per cache line. |
---|
| 18 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 19 | |
---|
| 20 | typedef struct spin_lock_s |
---|
| 21 | { |
---|
| 22 | unsigned int current; // current slot index |
---|
| 23 | unsigned int free; // next free slot index |
---|
| 24 | unsigned int padding[14]; // for 64 bytes alignment |
---|
| 25 | } spin_lock_t; |
---|
| 26 | |
---|
| 27 | typedef struct simple_lock_s |
---|
| 28 | { |
---|
| 29 | unsigned int value; |
---|
| 30 | unsigned int padding[15]; |
---|
| 31 | } simple_lock_t; |
---|
| 32 | |
---|
| 33 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 34 | // Locks access functions |
---|
| 35 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 36 | |
---|
| 37 | extern unsigned int _atomic_increment( unsigned int* ptr, |
---|
| 38 | unsigned int increment ); |
---|
| 39 | |
---|
| 40 | extern void _lock_init( spin_lock_t* lock ); |
---|
| 41 | |
---|
| 42 | extern void _lock_acquire( spin_lock_t* lock ); |
---|
| 43 | |
---|
| 44 | extern void _lock_release( spin_lock_t* lock ); |
---|
| 45 | |
---|
| 46 | extern void _simple_lock_acquire( simple_lock_t* lock ); |
---|
| 47 | |
---|
| 48 | extern void _simple_lock_release( simple_lock_t* lock ); |
---|
| 49 | |
---|
| 50 | #endif |
---|
| 51 | |
---|
| 52 | // Local Variables: |
---|
| 53 | // tab-width: 4 |
---|
| 54 | // c-basic-offset: 4 |
---|
| 55 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 56 | // indent-tabs-mode: nil |
---|
| 57 | // End: |
---|
| 58 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 59 | |
---|