Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 43bf393

Browse filesBrowse files
h2zerome-no-dev
authored andcommitted
Fix semaphores in IDF & std::string assert (espressif#2728)
* Fix semaphores in IDF & std::string assert Fixes the problem of giving a mutex from a callback with the latest IDF. Also addresses an occasional assert that happens when the btc_task callback gives the semaphore and causes an assert due to both cores potentially writing m_owner concurrently. * Restored m_owner position in wait() as requested * Reapply assert fix and move setting m_owner in ::give() Revert previous revert commit and move setting of m_owner in ::give to before giving the semaphore to prevent race condition possibility.
1 parent bea7bd1 commit 43bf393
Copy full SHA for 43bf393

File tree

1 file changed

+5
-6
lines changed
Filter options

1 file changed

+5
-6
lines changed

‎libraries/BLE/src/FreeRTOS.cpp

Copy file name to clipboardExpand all lines: libraries/BLE/src/FreeRTOS.cpp
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,20 @@ uint32_t FreeRTOS::getTimeSinceStart() {
6161
*/
6262
uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
6363
log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str());
64-
64+
6565
if (m_usePthreads) {
6666
pthread_mutex_lock(&m_pthread_mutex);
6767
} else {
6868
xSemaphoreTake(m_semaphore, portMAX_DELAY);
6969
}
7070

71-
m_owner = owner;
72-
7371
if (m_usePthreads) {
7472
pthread_mutex_unlock(&m_pthread_mutex);
7573
} else {
7674
xSemaphoreGive(m_semaphore);
7775
}
7876

7977
log_v("<< wait: Semaphore released: %s", toString().c_str());
80-
m_owner = std::string("<N/A>");
8178
return m_value;
8279
} // wait
8380

@@ -87,7 +84,8 @@ FreeRTOS::Semaphore::Semaphore(std::string name) {
8784
if (m_usePthreads) {
8885
pthread_mutex_init(&m_pthread_mutex, nullptr);
8986
} else {
90-
m_semaphore = xSemaphoreCreateMutex();
87+
m_semaphore = xSemaphoreCreateBinary();
88+
xSemaphoreGive(m_semaphore);
9189
}
9290

9391
m_name = name;
@@ -111,6 +109,8 @@ FreeRTOS::Semaphore::~Semaphore() {
111109
*/
112110
void FreeRTOS::Semaphore::give() {
113111
log_v("Semaphore giving: %s", toString().c_str());
112+
m_owner = std::string("<N/A>");
113+
114114
if (m_usePthreads) {
115115
pthread_mutex_unlock(&m_pthread_mutex);
116116
} else {
@@ -120,7 +120,6 @@ void FreeRTOS::Semaphore::give() {
120120
// FreeRTOS::sleep(10);
121121
// #endif
122122

123-
m_owner = std::string("<N/A>");
124123
} // Semaphore::give
125124

126125

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.