forked from philbowles/H4AsyncTCP
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LwIPCoreLocker.cpp
62 lines (55 loc) · 1.2 KB
/
LwIPCoreLocker.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
#include <H4AsyncTCP.h>
#include "lwipopts.h"
#include "lwip/tcpip.h"
volatile int LwIPCoreLocker::_locks=0;
#define PRINTAPPENDS "\t=====LOCKER=====\t"
LwIPCoreLocker::LwIPCoreLocker() {
#if H4AT_HAS_RTOS
lock();
#endif
}
void LwIPCoreLocker::unlock()
{
#if H4AT_HAS_RTOS
H4AT_PRINT4(PRINTAPPENDS"LwIPCoreLocker::unlock _locks=%d _locked=%d\n", _locks, _locked);
if (strcmp(H4AS_RTOS_GET_THREAD_NAME, TCPIP_THREAD_NAME) == 0)
{
H4AT_PRINT4(PRINTAPPENDS"Don't UNLOCK from LWIP THREAD\n");
return;
}
if (_locked){
_locks = _locks - 1;
if (_locks == 0) {
UNLOCK_TCPIP_CORE();
_locked=false;
}
}
#endif
}
LwIPCoreLocker::~LwIPCoreLocker()
{
#if H4AT_HAS_RTOS
H4AT_PRINT4(PRINTAPPENDS"~LwIPCoreLocker\n");
unlock();
#endif
}
void LwIPCoreLocker::lock()
{
#if H4AT_HAS_RTOS
H4AT_PRINT4(PRINTAPPENDS"LwIPCoreLocker _locks=%d _locked=%d\n", _locks, _locked);
if (_locked) {
H4AT_PRINT4(PRINTAPPENDS "LwIPCoreLocker Already locked\n");
return;
}
if (strcmp(H4AS_RTOS_GET_THREAD_NAME, TCPIP_THREAD_NAME) == 0)
{
H4AT_PRINT4(PRINTAPPENDS"Don't LOCK from LWIP THREAD\n");
return;
}
if (!_locks) { // The first lock
LOCK_TCPIP_CORE();
}
_locks = _locks + 1;
_locked=true;
#endif
}