-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbedTlsThreading.cpp
64 lines (51 loc) · 1.77 KB
/
mbedTlsThreading.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
/**
* \file
* \brief Definitions of threading-related functions for mbed TLS
*
* \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 "mbedtls/threading.h"
#include "distortos/BIND_LOW_LEVEL_INITIALIZER.h"
#include <cassert>
namespace
{
/*---------------------------------------------------------------------------------------------------------------------+
| local functions
+---------------------------------------------------------------------------------------------------------------------*/
void mbedTlsMutexFree(mbedtls_threading_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_destruct(mutex);
assert(ret == 0);
}
int mbedTlsMutexLock(mbedtls_threading_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_lock(mutex);
assert(ret == 0);
return {};
}
void mbedTlsMutexInit(mbedtls_threading_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_construct_1p(mutex, distortos_Mutex_Protocol_priorityInheritance);
assert(ret == 0);
}
int mbedTlsMutexUnlock(mbedtls_threading_mutex_t* const mutex)
{
const auto ret = distortos_Mutex_unlock(mutex);
assert(ret == 0);
return {};
}
/**
* \brief Low-level initializer for mbed TLS threading
*
* This function is called before constructors for global and static objects via BIND_LOW_LEVEL_INITIALIZER().
*/
void mbedTlsThreadingLowLevelInitializer()
{
mbedtls_threading_set_alt(mbedTlsMutexInit, mbedTlsMutexFree, mbedTlsMutexLock, mbedTlsMutexUnlock);
}
BIND_LOW_LEVEL_INITIALIZER(69, mbedTlsThreadingLowLevelInitializer);
} // namespace