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

Last change on this file since 762 was 709, checked in by alain, 9 years ago

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
  • Property svn:executable set to *
File size: 3.4 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,
[709]22                                       int           increment );
[632]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
[709]30extern unsigned int _atomic_test_and_set( unsigned int* ptr,
31                                          unsigned int  value );
32
[632]33//////////////////////////////////////////////////////////////////////////////
[466]34//      Simple lock structure and access functions
[523]35//////////////////////////////////////////////////////////////////////////////
[455]36
37typedef struct simple_lock_s
38{
[466]39    unsigned int value;          // lock taken if non zero
40    unsigned int padding[15];    // for 64 bytes alignment
[455]41} simple_lock_t;
42
[466]43extern void _simple_lock_acquire( simple_lock_t* lock );
44
45extern void _simple_lock_release( simple_lock_t* lock );
46
[523]47//////////////////////////////////////////////////////////////////////////////
[466]48//      Queuing lock structure and access functions
[523]49//////////////////////////////////////////////////////////////////////////////
[455]50
[466]51typedef struct spin_lock_s
52{
[495]53    unsigned int current;        // current slot index:
[466]54    unsigned int free;           // next free tiket index
55    unsigned int padding[14];    // for 64 bytes alignment
56} spin_lock_t;
57
58extern void _spin_lock_init( spin_lock_t* lock );
[455]59
[466]60extern void _spin_lock_acquire( spin_lock_t* lock );
[455]61
[466]62extern void _spin_lock_release( spin_lock_t* lock );
[455]63
[495]64
[523]65/////////////////////////////////////////////////////////////////////////////
[495]66//      SQT lock structures and access functions
[523]67/////////////////////////////////////////////////////////////////////////////
[455]68
[495]69typedef struct sqt_lock_node_s
[466]70{
[495]71    unsigned int            current;         // current ticket index
72    unsigned int            free;            // next free ticket index
[466]73    unsigned int            level;           // hierarchical level (0 is bottom)
[495]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;
[455]78
[495]79typedef struct sqt_lock_s
[466]80{
[495]81    sqt_lock_node_t* node[X_SIZE][Y_SIZE][5];  // array of pointers on SBT nodes
82} sqt_lock_t;
[466]83
[495]84extern void _sqt_lock_init( sqt_lock_t*   lock );
[466]85
[495]86extern void _sqt_lock_acquire( sqt_lock_t*  lock );
[466]87
[495]88extern void _sqt_lock_release( sqt_lock_t*  lock );
[466]89
[495]90
[455]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
Note: See TracBrowser for help on using the repository browser.