YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
include
interface
mutex_interface.h
1
// ---------------------------------------------
2
// This file is part of
3
// _ _ __ _ _ __ __
4
// ( \/ ) /__\ ( )_( ) /__\ ( )
5
// \ / /(__)\ ) _ ( /(__)\ )(__
6
// (__)(__)(__)(_) (_)(__)(__)(____)
7
//
8
// Yet Another HW Abstraction Library
9
// Copyright (C) Andreas Terstegge
10
// BSD Licensed (see file LICENSE)
11
//
12
// ---------------------------------------------
13
//
14
// This file defines a generic and abstract C++
15
// interface for a simple mutex. A concrete class
16
// implementing this interface will typically use an
17
// instance implementing the lock_base_interface.
18
//
19
// Note that lock() and unlock() have to be called from
20
// the same task! Otherwise an assertion should fail.
21
// There are 3 modes for a mutex when waiting for the lock.
22
// The mode is typically specified as the constructor
23
// parameter (not part of this interface!).
24
//
25
// ACTIVE_WAIT:
26
// The mutex actively polls for the lock. This makes sense
27
// if e.g. a HW trigger/IRQ handler releases the lock.
28
//
29
// YIELD:
30
// The mutex passes back the control to the scheduler, but
31
// does not block the task.
32
//
33
// BLOCK:
34
// The task is blocked and does not get any further time
35
// slices until the lock is unlocked. This is also the
36
// default mode!
37
//
38
39
#ifndef _MUTEX_INTERFACE_H_
40
#define _MUTEX_INTERFACE_H_
41
42
namespace
MUTEX {
43
enum
mutex_type { ACTIVE_WAIT, YIELD, BLOCK };
44
}
45
46
class
mutex_interface
{
47
public
:
48
// Lock the mutex
49
virtual
void
lock() = 0;
50
51
// Unlock the mutex
52
virtual
void
unlock() = 0;
53
54
// Try to lock. Return true on success.
55
virtual
bool
try_lock() = 0;
56
57
protected
:
58
virtual
~mutex_interface
() =
default
;
59
};
60
61
#endif
/* _MUTEX_INTERFACE_H_ */
mutex_interface
Definition
mutex_interface.h:46
Generated by
1.12.0