source: soft/giet_vm/giet_common/kernel_locks.h @ 667

Last change on this file since 667 was 632, checked in by alain, 9 years ago

Introduce two new atomic read-the-write functions, that can be used
to set or reset a bit field in a shared 32 bits word:

_atomic_or()
_atpmic_and()

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