[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. |
---|
[466] | 8 | // They define both atomic increment operations and three types of locks. |
---|
[455] | 9 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 10 | |
---|
| 11 | #ifndef GIET_LOCKS_H |
---|
| 12 | #define GIET_LOCKS_H |
---|
| 13 | |
---|
[466] | 14 | #include "hard_config.h" |
---|
| 15 | |
---|
[455] | 16 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[466] | 17 | // Simple lock structure and access functions |
---|
[455] | 18 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 19 | |
---|
| 20 | typedef struct simple_lock_s |
---|
| 21 | { |
---|
[466] | 22 | unsigned int value; // lock taken if non zero |
---|
| 23 | unsigned int padding[15]; // for 64 bytes alignment |
---|
[455] | 24 | } simple_lock_t; |
---|
| 25 | |
---|
[466] | 26 | extern void _simple_lock_acquire( simple_lock_t* lock ); |
---|
| 27 | |
---|
| 28 | extern void _simple_lock_release( simple_lock_t* lock ); |
---|
| 29 | |
---|
[455] | 30 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[466] | 31 | // Queuing lock structure and access functions |
---|
[455] | 32 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 33 | |
---|
[466] | 34 | typedef struct spin_lock_s |
---|
| 35 | { |
---|
| 36 | unsigned int current; // current slot index |
---|
| 37 | unsigned int free; // next free tiket index |
---|
| 38 | unsigned int padding[14]; // for 64 bytes alignment |
---|
| 39 | } spin_lock_t; |
---|
| 40 | |
---|
[455] | 41 | extern unsigned int _atomic_increment( unsigned int* ptr, |
---|
| 42 | unsigned int increment ); |
---|
| 43 | |
---|
[466] | 44 | extern void _spin_lock_init( spin_lock_t* lock ); |
---|
[455] | 45 | |
---|
[466] | 46 | extern void _spin_lock_acquire( spin_lock_t* lock ); |
---|
[455] | 47 | |
---|
[466] | 48 | extern void _spin_lock_release( spin_lock_t* lock ); |
---|
[455] | 49 | |
---|
[466] | 50 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 51 | // SBT lock structures and access functions |
---|
| 52 | ////////////////////////////////////////////////////////////////////////////////// |
---|
[455] | 53 | |
---|
[466] | 54 | typedef struct lock_node_s |
---|
| 55 | { |
---|
| 56 | unsigned int taken; // lock taken if non zero |
---|
| 57 | unsigned int level; // hierarchical level (0 is bottom) |
---|
| 58 | struct lock_node_s* parent; // pointer on parent node (NULL for root) |
---|
| 59 | struct lock_node_s* child0; // pointer on children node |
---|
| 60 | struct lock_node_s* child1; // pointer on children node |
---|
| 61 | unsigned int x; // cluster x coordinate |
---|
| 62 | unsigned int y; // cluster y coordinate |
---|
| 63 | unsigned int padding[9]; // for 64 bytes alignment |
---|
| 64 | } lock_node_t; |
---|
[455] | 65 | |
---|
[466] | 66 | typedef struct sbt_lock_s |
---|
| 67 | { |
---|
| 68 | unsigned int ntasks; // total number of expected tasks |
---|
| 69 | lock_node_t* node[X_SIZE][Y_SIZE][9]; // array of pointers on SBT nodes |
---|
| 70 | } sbt_lock_t; |
---|
| 71 | |
---|
| 72 | extern void _sbt_lock_init( sbt_lock_t* lock ); |
---|
| 73 | |
---|
| 74 | extern void _sbt_lock_acquire( sbt_lock_t* lock ); |
---|
| 75 | |
---|
| 76 | extern void _sbt_lock_release( sbt_lock_t* lock ); |
---|
| 77 | |
---|
[455] | 78 | #endif |
---|
| 79 | |
---|
| 80 | // Local Variables: |
---|
| 81 | // tab-width: 4 |
---|
| 82 | // c-basic-offset: 4 |
---|
| 83 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 84 | // indent-tabs-mode: nil |
---|
| 85 | // End: |
---|
| 86 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 87 | |
---|