Skip to content

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

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 4 commits into from
May 11, 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
11 changes: 5 additions & 6 deletions libraries/BLE/src/FreeRTOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,20 @@ uint32_t FreeRTOS::getTimeSinceStart() {
*/
uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str());

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);
}

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

Expand All @@ -87,7 +84,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 All @@ -111,6 +109,8 @@ FreeRTOS::Semaphore::~Semaphore() {
*/
void FreeRTOS::Semaphore::give() {
log_v("Semaphore giving: %s", toString().c_str());
m_owner = std::string("<N/A>");

if (m_usePthreads) {
pthread_mutex_unlock(&m_pthread_mutex);
} else {
Expand All @@ -120,7 +120,6 @@ void FreeRTOS::Semaphore::give() {
// FreeRTOS::sleep(10);
// #endif

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


Expand Down