User | Revision | Line number | New contents of line |
switches |
0:0e018d759a2a
|
1
|
/* mbed Microcontroller Library
|
switches |
0:0e018d759a2a
|
2
|
* Copyright (c) 2006-2012 ARM Limited
|
switches |
0:0e018d759a2a
|
3
|
*
|
switches |
0:0e018d759a2a
|
4
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
switches |
0:0e018d759a2a
|
5
|
* of this software and associated documentation files (the "Software"), to deal
|
switches |
0:0e018d759a2a
|
6
|
* in the Software without restriction, including without limitation the rights
|
switches |
0:0e018d759a2a
|
7
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
switches |
0:0e018d759a2a
|
8
|
* copies of the Software, and to permit persons to whom the Software is
|
switches |
0:0e018d759a2a
|
9
|
* furnished to do so, subject to the following conditions:
|
switches |
0:0e018d759a2a
|
10
|
*
|
switches |
0:0e018d759a2a
|
11
|
* The above copyright notice and this permission notice shall be included in
|
switches |
0:0e018d759a2a
|
12
|
* all copies or substantial portions of the Software.
|
switches |
0:0e018d759a2a
|
13
|
*
|
switches |
0:0e018d759a2a
|
14
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
switches |
0:0e018d759a2a
|
15
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
switches |
0:0e018d759a2a
|
16
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
switches |
0:0e018d759a2a
|
17
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
switches |
0:0e018d759a2a
|
18
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
switches |
0:0e018d759a2a
|
19
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
switches |
0:0e018d759a2a
|
20
|
* SOFTWARE.
|
switches |
0:0e018d759a2a
|
21
|
*/
|
switches |
0:0e018d759a2a
|
22
|
#ifndef MUTEX_H
|
switches |
0:0e018d759a2a
|
23
|
#define MUTEX_H
|
switches |
0:0e018d759a2a
|
24
|
|
switches |
0:0e018d759a2a
|
25
|
#include <stdint.h>
|
switches |
0:0e018d759a2a
|
26
|
#include "cmsis_os.h"
|
switches |
0:0e018d759a2a
|
27
|
|
switches |
0:0e018d759a2a
|
28
|
namespace rtos {
|
switches |
0:0e018d759a2a
|
29
|
/** \addtogroup rtos */
|
switches |
0:0e018d759a2a
|
30
|
/** @{*/
|
switches |
0:0e018d759a2a
|
31
|
|
switches |
0:0e018d759a2a
|
32
|
/** The Mutex class is used to synchronise the execution of threads.
|
switches |
0:0e018d759a2a
|
33
|
This is for example used to protect access to a shared resource.
|
switches |
0:0e018d759a2a
|
34
|
*/
|
switches |
0:0e018d759a2a
|
35
|
class Mutex {
|
switches |
0:0e018d759a2a
|
36
|
public:
|
switches |
0:0e018d759a2a
|
37
|
/** Create and Initialize a Mutex object */
|
switches |
0:0e018d759a2a
|
38
|
Mutex();
|
switches |
0:0e018d759a2a
|
39
|
|
switches |
0:0e018d759a2a
|
40
|
/** Wait until a Mutex becomes available.
|
switches |
0:0e018d759a2a
|
41
|
@param millisec timeout value or 0 in case of no time-out. (default: osWaitForever)
|
switches |
0:0e018d759a2a
|
42
|
@return status code that indicates the execution status of the function.
|
switches |
0:0e018d759a2a
|
43
|
*/
|
switches |
0:0e018d759a2a
|
44
|
osStatus lock(uint32_t millisec=osWaitForever);
|
switches |
0:0e018d759a2a
|
45
|
|
switches |
0:0e018d759a2a
|
46
|
/** Try to lock the mutex, and return immediately
|
switches |
0:0e018d759a2a
|
47
|
@return true if the mutex was acquired, false otherwise.
|
switches |
0:0e018d759a2a
|
48
|
*/
|
switches |
0:0e018d759a2a
|
49
|
bool trylock();
|
switches |
0:0e018d759a2a
|
50
|
|
switches |
0:0e018d759a2a
|
51
|
/** Unlock the mutex that has previously been locked by the same thread
|
switches |
0:0e018d759a2a
|
52
|
@return status code that indicates the execution status of the function.
|
switches |
0:0e018d759a2a
|
53
|
*/
|
switches |
0:0e018d759a2a
|
54
|
osStatus unlock();
|
switches |
0:0e018d759a2a
|
55
|
|
switches |
0:0e018d759a2a
|
56
|
~Mutex();
|
switches |
0:0e018d759a2a
|
57
|
|
switches |
0:0e018d759a2a
|
58
|
private:
|
switches |
0:0e018d759a2a
|
59
|
osMutexId _osMutexId;
|
switches |
0:0e018d759a2a
|
60
|
osMutexDef_t _osMutexDef;
|
switches |
0:0e018d759a2a
|
61
|
#ifdef CMSIS_OS_RTX
|
switches |
0:0e018d759a2a
|
62
|
#if defined(__MBED_CMSIS_RTOS_CA9) || defined(__MBED_CMSIS_RTOS_CM)
|
switches |
0:0e018d759a2a
|
63
|
int32_t _mutex_data[4];
|
switches |
0:0e018d759a2a
|
64
|
#else
|
switches |
0:0e018d759a2a
|
65
|
int32_t _mutex_data[3];
|
switches |
0:0e018d759a2a
|
66
|
#endif
|
switches |
0:0e018d759a2a
|
67
|
#endif
|
switches |
0:0e018d759a2a
|
68
|
};
|
switches |
0:0e018d759a2a
|
69
|
|
switches |
0:0e018d759a2a
|
70
|
}
|
switches |
0:0e018d759a2a
|
71
|
#endif
|
switches |
0:0e018d759a2a
|
72
|
|
switches |
0:0e018d759a2a
|
73
|
/** @}*/
|