1 | ////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : kernel_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 three types of locks. |
---|
9 | ////////////////////////////////////////////////////////////////////////////// |
---|
10 | |
---|
11 | #ifndef GIET_LOCKS_H |
---|
12 | #define GIET_LOCKS_H |
---|
13 | |
---|
14 | #include "hard_config.h" |
---|
15 | |
---|
16 | |
---|
17 | ////////////////////////////////////////////////////////////////////////////// |
---|
18 | // Atomic access functions using LL/SC instructions |
---|
19 | ////////////////////////////////////////////////////////////////////////////// |
---|
20 | |
---|
21 | extern unsigned int _atomic_increment( unsigned int* ptr, |
---|
22 | int increment ); |
---|
23 | |
---|
24 | extern void _atomic_or( unsigned int* ptr, |
---|
25 | unsigned int mask ); |
---|
26 | |
---|
27 | extern void _atomic_and( unsigned int* ptr, |
---|
28 | unsigned int mask ); |
---|
29 | |
---|
30 | extern unsigned int _atomic_test_and_set( unsigned int* ptr, |
---|
31 | unsigned int value ); |
---|
32 | |
---|
33 | ////////////////////////////////////////////////////////////////////////////// |
---|
34 | // Simple lock structure and access functions |
---|
35 | ////////////////////////////////////////////////////////////////////////////// |
---|
36 | |
---|
37 | typedef struct simple_lock_s |
---|
38 | { |
---|
39 | unsigned int value; // lock taken if non zero |
---|
40 | unsigned int padding[15]; // for 64 bytes alignment |
---|
41 | } simple_lock_t; |
---|
42 | |
---|
43 | extern void _simple_lock_acquire( simple_lock_t* lock ); |
---|
44 | |
---|
45 | extern void _simple_lock_release( simple_lock_t* lock ); |
---|
46 | |
---|
47 | ////////////////////////////////////////////////////////////////////////////// |
---|
48 | // Queuing lock structure and access functions |
---|
49 | ////////////////////////////////////////////////////////////////////////////// |
---|
50 | |
---|
51 | typedef struct spin_lock_s |
---|
52 | { |
---|
53 | unsigned int current; // current slot index: |
---|
54 | unsigned int free; // next free tiket index |
---|
55 | unsigned int padding[14]; // for 64 bytes alignment |
---|
56 | } spin_lock_t; |
---|
57 | |
---|
58 | extern void _spin_lock_init( spin_lock_t* lock ); |
---|
59 | |
---|
60 | extern void _spin_lock_acquire( spin_lock_t* lock ); |
---|
61 | |
---|
62 | extern void _spin_lock_release( spin_lock_t* lock ); |
---|
63 | |
---|
64 | |
---|
65 | ///////////////////////////////////////////////////////////////////////////// |
---|
66 | // SQT lock structures and access functions |
---|
67 | ///////////////////////////////////////////////////////////////////////////// |
---|
68 | |
---|
69 | typedef struct sqt_lock_node_s |
---|
70 | { |
---|
71 | unsigned int current; // current ticket index |
---|
72 | unsigned int free; // next free ticket index |
---|
73 | unsigned int level; // hierarchical level (0 is bottom) |
---|
74 | struct sqt_lock_node_s* parent; // parent node (NULL for root) |
---|
75 | struct sqt_lock_node_s* child[4]; // children node |
---|
76 | unsigned int padding[8]; // for 64 bytes alignment |
---|
77 | } sqt_lock_node_t; |
---|
78 | |
---|
79 | typedef struct sqt_lock_s |
---|
80 | { |
---|
81 | sqt_lock_node_t* node[X_SIZE][Y_SIZE][5]; // array of pointers on SBT nodes |
---|
82 | } sqt_lock_t; |
---|
83 | |
---|
84 | extern void _sqt_lock_init( sqt_lock_t* lock ); |
---|
85 | |
---|
86 | extern void _sqt_lock_acquire( sqt_lock_t* lock ); |
---|
87 | |
---|
88 | extern void _sqt_lock_release( sqt_lock_t* lock ); |
---|
89 | |
---|
90 | |
---|
91 | #endif |
---|
92 | |
---|
93 | // Local Variables: |
---|
94 | // tab-width: 4 |
---|
95 | // c-basic-offset: 4 |
---|
96 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
97 | // indent-tabs-mode: nil |
---|
98 | // End: |
---|
99 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
100 | |
---|