File tree Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Expand file tree Collapse file tree 3 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -57,7 +57,12 @@ bool WiFiClient::getDefaultSync() {
5757
5858template <>
5959WiFiClient* SList<WiFiClient>::_s_first = 0 ;
60-
60+ #ifdef __FREERTOS
61+ template <>
62+ SemaphoreHandle_t SList<WiFiClient>::_s_first_lock = 0 ;
63+ template <>
64+ bool SList<WiFiClient>::_s_first_lock_created = false ;
65+ #endif
6166
6267WiFiClient::WiFiClient ()
6368 : _client(0 ), _owned(0 ) {
Original file line number Diff line number Diff line change 3636
3737template <>
3838WiFiUDP* SList<WiFiUDP>::_s_first = 0 ;
39+ #ifdef __FREERTOS
40+ template <>
41+ SemaphoreHandle_t SList<WiFiUDP>::_s_first_lock = 0 ;
42+ template <>
43+ bool SList<WiFiUDP>::_s_first_lock_created = false ;
44+ #endif
45+
3946
4047/* Constructor */
4148WiFiUDP::WiFiUDP () : _ctx(0 ), _multicast(false ), _dirty(false ) {
Original file line number Diff line number Diff line change 11#ifndef SLIST_H
22#define SLIST_H
33
4+ #ifdef __FREERTOS
5+ #include " FreeRTOS.h"
6+ #include " semphr.h"
7+ #endif
8+
49template <typename T>
510class SList {
611public:
@@ -9,27 +14,58 @@ class SList {
914protected:
1015
1116 static void _add (T* self) {
17+ #ifdef __FREERTOS
18+ if (!_s_first_lock_created) {
19+ _s_first_lock_created = true ;
20+ _s_first_lock = xSemaphoreCreateMutex ();
21+ }
22+ xSemaphoreTake (_s_first_lock, portMAX_DELAY);
23+ #endif
1224 T* tmp = _s_first;
1325 _s_first = self;
1426 self->_next = tmp;
27+ #ifdef __FREERTOS
28+ xSemaphoreGive (_s_first_lock);
29+ #endif
1530 }
1631
1732 static void _remove (T* self) {
33+ #ifdef __FREERTOS
34+ if (!_s_first_lock_created) {
35+ _s_first_lock_created = true ;
36+ _s_first_lock = xSemaphoreCreateMutex ();
37+ }
38+ xSemaphoreTake (_s_first_lock, portMAX_DELAY);
39+ #endif
40+
1841 if (_s_first == self) {
1942 _s_first = self->_next ;
2043 self->_next = 0 ;
44+ #ifdef __FREERTOS
45+ xSemaphoreGive (_s_first_lock);
46+ #endif
2147 return ;
2248 }
2349
2450 for (T* prev = _s_first; prev->_next ; prev = prev->_next ) {
2551 if (prev->_next == self) {
2652 prev->_next = self->_next ;
2753 self->_next = 0 ;
54+ #ifdef __FREERTOS
55+ xSemaphoreGive (_s_first_lock);
56+ #endif
2857 return ;
2958 }
3059 }
60+ #ifdef __FREERTOS
61+ xSemaphoreGive (_s_first_lock);
62+ #endif
3163 }
3264
65+ #ifdef __FREERTOS
66+ static SemaphoreHandle_t _s_first_lock;
67+ static bool _s_first_lock_created;
68+ #endif
3369 static T* _s_first;
3470 T* _next;
3571};
You can’t perform that action at this time.
0 commit comments