[523] | 1 | ////////////////////////////////////////////////////////////////////////////// |
---|
[495] | 2 | // File : kernel_locks.h |
---|
[455] | 3 | // Date : 01/12/2014 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
[523] | 6 | ////////////////////////////////////////////////////////////////////////////// |
---|
[455] | 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. |
---|
[523] | 9 | ////////////////////////////////////////////////////////////////////////////// |
---|
[455] | 10 | |
---|
| 11 | #ifndef GIET_LOCKS_H |
---|
| 12 | #define GIET_LOCKS_H |
---|
| 13 | |
---|
[466] | 14 | #include "hard_config.h" |
---|
| 15 | |
---|
[523] | 16 | ////////////////////////////////////////////////////////////////////////////// |
---|
[466] | 17 | // Simple lock structure and access functions |
---|
[523] | 18 | ////////////////////////////////////////////////////////////////////////////// |
---|
[455] | 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 | |
---|
[523] | 30 | ////////////////////////////////////////////////////////////////////////////// |
---|
[466] | 31 | // Queuing lock structure and access functions |
---|
[523] | 32 | ////////////////////////////////////////////////////////////////////////////// |
---|
[455] | 33 | |
---|
[466] | 34 | typedef struct spin_lock_s |
---|
| 35 | { |
---|
[495] | 36 | unsigned int current; // current slot index: |
---|
[466] | 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, |
---|
[495] | 42 | int increment ); |
---|
[455] | 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 | |
---|
[495] | 50 | |
---|
[523] | 51 | ///////////////////////////////////////////////////////////////////////////// |
---|
[495] | 52 | // SQT lock structures and access functions |
---|
[523] | 53 | ///////////////////////////////////////////////////////////////////////////// |
---|
[455] | 54 | |
---|
[495] | 55 | typedef struct sqt_lock_node_s |
---|
[466] | 56 | { |
---|
[495] | 57 | unsigned int current; // current ticket index |
---|
| 58 | unsigned int free; // next free ticket index |
---|
[466] | 59 | unsigned int level; // hierarchical level (0 is bottom) |
---|
[495] | 60 | struct sqt_lock_node_s* parent; // parent node (NULL for root) |
---|
| 61 | struct sqt_lock_node_s* child[4]; // children node |
---|
| 62 | unsigned int padding[8]; // for 64 bytes alignment |
---|
| 63 | } sqt_lock_node_t; |
---|
[455] | 64 | |
---|
[495] | 65 | typedef struct sqt_lock_s |
---|
[466] | 66 | { |
---|
[495] | 67 | sqt_lock_node_t* node[X_SIZE][Y_SIZE][5]; // array of pointers on SBT nodes |
---|
| 68 | } sqt_lock_t; |
---|
[466] | 69 | |
---|
[495] | 70 | extern void _sqt_lock_init( sqt_lock_t* lock ); |
---|
[466] | 71 | |
---|
[495] | 72 | extern void _sqt_lock_acquire( sqt_lock_t* lock ); |
---|
[466] | 73 | |
---|
[495] | 74 | extern void _sqt_lock_release( sqt_lock_t* lock ); |
---|
[466] | 75 | |
---|
[495] | 76 | |
---|
[455] | 77 | #endif |
---|
| 78 | |
---|
| 79 | // Local Variables: |
---|
| 80 | // tab-width: 4 |
---|
| 81 | // c-basic-offset: 4 |
---|
| 82 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 83 | // indent-tabs-mode: nil |
---|
| 84 | // End: |
---|
| 85 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 86 | |
---|