-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlwipMutex.cpp
67 lines (54 loc) · 1.88 KB
/
lwipMutex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* \file
* \brief Definitions of mutex-related functions for lwIP
*
* \author Copyright (C) 2019-2022 Kamil Szczygiel http://www.distortec.com http://www.freddiechopin.info
*
* \par License
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
* distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "lwip/sys.h"
#include <cassert>
#include <cstring>
namespace
{
/*---------------------------------------------------------------------------------------------------------------------+
| local objects
+---------------------------------------------------------------------------------------------------------------------*/
/// distortos_Mutex in an invalid state, real object will never match this one
const struct distortos_Mutex invalidMutex {};
} // namespace
/*---------------------------------------------------------------------------------------------------------------------+
| global functions
+---------------------------------------------------------------------------------------------------------------------*/
void sys_mutex_free(sys_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_destruct(mutex);
assert(ret == 0);
}
void sys_mutex_lock(sys_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_lock(mutex);
assert(ret == 0);
}
err_t sys_mutex_new(sys_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_construct_1p(mutex, distortos_Mutex_Protocol_priorityInheritance);
assert(ret == 0);
return ERR_OK;
}
void sys_mutex_set_invalid(sys_mutex_t* const mutex)
{
memcpy(mutex, &invalidMutex, sizeof(*mutex));
}
void sys_mutex_unlock(sys_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_unlock(mutex);
assert(ret == 0);
}
int sys_mutex_valid(sys_mutex_t* const mutex)
{
const auto ret = memcmp(mutex, &invalidMutex, sizeof(*mutex));
return ret != 0;
}