8000 Fix semaphores in IDF & std::string assert by h2zero · Pull Request #1 · h2zero/esp32-snippets · GitHub
[go: up one dir, main page]

Skip to content

Fix semaphores in IDF & std::string assert #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cpp_utils/FreeRTOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,22 @@ uint32_t FreeRTOS::getTimeSinceStart() {
*/
uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
ESP_LOGV(LOG_TAG, ">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str());

m_owner = owner;

if (m_usePthreads) {
pthread_mutex_lock(&m_pthread_mutex);
} else {
xSemaphoreTake(m_semaphore, portMAX_DELAY);
}

m_owner = owner;

if (m_usePthreads) {
pthread_mutex_unlock(&m_pthread_mutex);
} else {
xSemaphoreGive(m_semaphore);
}

ESP_LOGV(LOG_TAG, "<< wait: Semaphore released: %s", toString().c_str());
m_owner = std::string("<N/A>");
return m_value;
} // wait

Expand All @@ -93,7 +92,8 @@ FreeRTOS::Semaphore::Semaphore(std::string name) {
if (m_usePthreads) {
pthread_mutex_init(&m_pthread_mutex, nullptr);
} else {
m_semaphore = xSemaphoreCreateMutex();
m_semaphore = xSemaphoreCreateBinary();
xSemaphoreGive(m_semaphore);
}

m_name = name;
Expand Down
0