| 1 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 2 | // File     : user_lock.h | 
|---|
| 3 | // Date     : 01/12/2014 | 
|---|
| 4 | // Author   : alain greiner | 
|---|
| 5 | // Copyright (c) UPMC-LIP6 | 
|---|
| 6 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 7 | // The file_lock.c and file_lock.h files are part of the GIET-VM nano-kernel. | 
|---|
| 8 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 9 |  | 
|---|
| 10 | #ifndef _USER_LOCK_H_ | 
|---|
| 11 | #define _USER_LOCK_H_ | 
|---|
| 12 |  | 
|---|
| 13 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 14 | //  simple lock structure | 
|---|
| 15 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 16 |  | 
|---|
| 17 | typedef struct user_lock_s | 
|---|
| 18 | { | 
|---|
| 19 | unsigned int current;        // current slot index | 
|---|
| 20 | unsigned int free;           // next free slot index | 
|---|
| 21 | unsigned int padding[14];    // for 64 bytes alignment | 
|---|
| 22 | } user_lock_t; | 
|---|
| 23 |  | 
|---|
| 24 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 25 | //  simple lock access functions | 
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 27 |  | 
|---|
| 28 | extern unsigned int atomic_increment( unsigned int* ptr, | 
|---|
| 29 | unsigned int  increment ); | 
|---|
| 30 |  | 
|---|
| 31 | extern void lock_acquire( user_lock_t * lock ); | 
|---|
| 32 |  | 
|---|
| 33 | extern void lock_release( user_lock_t * lock ); | 
|---|
| 34 |  | 
|---|
| 35 | extern void lock_init( user_lock_t * lock ); | 
|---|
| 36 |  | 
|---|
| 37 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 38 | //      SQT lock structures | 
|---|
| 39 | /////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 40 |  | 
|---|
| 41 | typedef struct sqt_lock_node_s | 
|---|
| 42 | { | 
|---|
| 43 | unsigned int            current;         // current ticket index | 
|---|
| 44 | unsigned int            free;            // next free ticket index | 
|---|
| 45 | unsigned int            level;           // hierarchical level (0 is bottom) | 
|---|
| 46 | struct sqt_lock_node_s* parent;          // parent node (NULL for root) | 
|---|
| 47 | struct sqt_lock_node_s* child[4];        // children node | 
|---|
| 48 | unsigned int            padding[8];      // for 64 bytes alignment | 
|---|
| 49 | } sqt_lock_node_t; | 
|---|
| 50 |  | 
|---|
| 51 | typedef struct sqt_lock_s | 
|---|
| 52 | { | 
|---|
| 53 | sqt_lock_node_t* node[16][16][5];        // array of pointers on SBT nodes (max size) | 
|---|
| 54 | } sqt_lock_t; | 
|---|
| 55 |  | 
|---|
| 56 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 57 | //      SQT lock access functions | 
|---|
| 58 | ////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 59 |  | 
|---|
| 60 |  | 
|---|
| 61 | extern void sqt_lock_init( sqt_lock_t*  lock, | 
|---|
| 62 | unsigned int         x_size, | 
|---|
| 63 | unsigned int         y_size, | 
|---|
| 64 | unsigned int         ntasks ); | 
|---|
| 65 |  | 
|---|
| 66 | extern void sqt_lock_acquire( sqt_lock_t*  lock ); | 
|---|
| 67 |  | 
|---|
| 68 | extern void sqt_lock_release( sqt_lock_t*  lock ); | 
|---|
| 69 |  | 
|---|
| 70 | #endif | 
|---|
| 71 |  | 
|---|
| 72 | // Local Variables: | 
|---|
| 73 | // tab-width: 4 | 
|---|
| 74 | // c-basic-offset: 4 | 
|---|
| 75 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) | 
|---|
| 76 | // indent-tabs-mode: nil | 
|---|
| 77 | // End: | 
|---|
| 78 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 | 
|---|
| 79 |  | 
|---|