-
Notifications
You must be signed in to change notification settings - Fork 58
/
dtls_mutex.h
70 lines (52 loc) · 2.07 KB
/
dtls_mutex.h
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
68
69
70
/*******************************************************************************
*
* Copyright (c) 2019 Olaf Bergmann (TZI) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompanies this distribution.
*
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Jon Shallow - Initall add in of generic mutex support
*
*******************************************************************************/
/**
* @file dtls_mutex.h
* @brief DTLS mutex mechanism wrapper
*/
#ifndef _DTLS_MUTEX_H_
#define _DTLS_MUTEX_H_
#if defined(RIOT_VERSION)
#include <mutex.h>
typedef mutex_t dtls_mutex_t;
#define DTLS_MUTEX_INITIALIZER MUTEX_INIT
#define dtls_mutex_lock(a) mutex_lock(a)
#define dtls_mutex_trylock(a) mutex_trylock(a)
#define dtls_mutex_unlock(a) mutex_unlock(a)
#elif defined(WITH_CONTIKI)
/* CONTIKI does not support mutex */
typedef int dtls_mutex_t;
#define DTLS_MUTEX_INITIALIZER 0
#define dtls_mutex_lock(a) *(a) = 1
#define dtls_mutex_trylock(a) *(a) = 1
#define dtls_mutex_unlock(a) *(a) = 0
#elif defined(WITH_ZEPHYR) || defined(IS_WINDOWS)
/* zephyr supports mutex, but this port doesn't use it */
// TODO: Add Windows compatible mutex definitions
typedef int dtls_mutex_t;
#define DTLS_MUTEX_INITIALIZER 0
#define dtls_mutex_lock(a) *(a) = 1
#define dtls_mutex_trylock(a) *(a) = 1
#define dtls_mutex_unlock(a) *(a) = 0
#else /* ! RIOT_VERSION && ! WITH_CONTIKI && ! WITH_ZEPHYR && ! IS_WINDOWS */
#include <pthread.h>
typedef pthread_mutex_t dtls_mutex_t;
#define DTLS_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define dtls_mutex_lock(a) pthread_mutex_lock(a)
#define dtls_mutex_trylock(a) pthread_mutex_trylock(a)
#define dtls_mutex_unlock(a) pthread_mutex_unlock(a)
#endif /* ! RIOT_VERSION && ! WITH_CONTIKI && ! IS_WINDOWS */
#endif /* _DTLS_MUTEX_H_ */