Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion erpc_c/port/erpc_setup_extensions_freertos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void erpc::erpc_pre_cb_default(void)
(void)s_erpc_call_in_progress->get(s_erpc_call_in_progress->kWaitForever);
erpc_assert(s_erpc_call_timer_cb &&
"If you want use default pre cb action, do not forget call erpc_init_call_progress_detection_default.");
xTimerStart(s_erpc_call_timer_cb, 0);
(void)xTimerStart(s_erpc_call_timer_cb, 0);
}

void erpc::erpc_post_cb_default(void)
Expand Down
6 changes: 3 additions & 3 deletions erpc_c/port/erpc_threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Thread
/*!
* @brief This function puts thread to sleep.
*
* @param[in] usecs Time for sleeping.
* @param[in] usecs Time for sleeping in [us].
*/
static void sleep(uint32_t usecs);

Expand Down Expand Up @@ -477,12 +477,12 @@ class Semaphore
/*!
* @brief This function get semaphore.
*
* @param[in] timeout Time how long can wait for getting semaphore.
* @param[in] timeoutUsecs Time how long can wait for getting semaphore in [us].
*
* @retval true When semaphore got successfully.
* @retval false When mutex didn't get.
*/
bool get(uint32_t timeout = kWaitForever);
bool get(uint32_t timeoutUsecs = kWaitForever);

/*!
* @brief This function returns semaphore count number.
Expand Down
28 changes: 19 additions & 9 deletions erpc_c/port/erpc_threading_freertos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,23 +264,33 @@ void Semaphore::putFromISR(void)
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}

bool Semaphore::get(uint32_t timeout)
bool Semaphore::get(uint32_t timeoutUsecs)
{
#if configUSE_16_BIT_TICKS
if (timeout == kWaitForever)
if (timeoutUsecs != kWaitForever)
{
timeout = portMAX_DELAY;
if (timeoutUsecs > 0U)
{
timeoutUsecs /= 1000U * portTICK_PERIOD_MS;
if (timeoutUsecs == 0U)
{
timeoutUsecs = 1U;
}
#if configUSE_16_BIT_TICKS
else if (timeoutUsecs > (portMAX_DELAY - 1))
{
timeoutUsecs = portMAX_DELAY - 1;
}
#endif
}
}
#if configUSE_16_BIT_TICKS
else
{
if (timeout > (portMAX_DELAY - 1))
{
timeout = portMAX_DELAY - 1;
}
timeoutUsecs = portMAX_DELAY;
}
#endif

return (pdTRUE == xSemaphoreTake(m_sem, timeout / 1000U / portTICK_PERIOD_MS));
return (pdTRUE == xSemaphoreTake(m_sem, (TickType_t)timeoutUsecs));
}

int Semaphore::getCount(void) const
Expand Down
16 changes: 14 additions & 2 deletions erpc_c/port/erpc_threading_mbed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,21 @@ void Semaphore::put(void)
m_sem->release();
}

bool Semaphore::get(uint32_t timeout)
bool Semaphore::get(uint32_t timeoutUsecs)
{
m_count = m_sem->wait(timeout);
if (timeoutUsecs != kWaitForever)
{
if (timeoutUsecs > 0U)
{
timeoutUsecs /= 1000U;
if (timeoutUsecs == 0U)
{
timeoutUsecs = 1U;
}
}
}

m_count = m_sem->wait(timeoutUsecs);
return (m_count < 0);
}

Expand Down
10 changes: 5 additions & 5 deletions erpc_c/port/erpc_threading_pthreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ void Semaphore::put(void)
++m_count;
}

bool Semaphore::get(uint32_t timeout)
bool Semaphore::get(uint32_t timeoutUsecs)
{
Mutex::Guard guard(m_mutex);
bool retVal = true;
int err;

while (m_count == 0)
{
if (timeout == kWaitForever)
if (timeoutUsecs == kWaitForever)
{
err = pthread_cond_wait(&m_cond, m_mutex.getPtr());
if (err != 0)
Expand All @@ -204,14 +204,14 @@ bool Semaphore::get(uint32_t timeout)
}
else
{
if (timeout > 0U)
if (timeoutUsecs > 0U)
{
// Create an absolute timeout time.
struct timeval tv;
gettimeofday(&tv, NULL);
struct timespec wait;
wait.tv_sec = tv.tv_sec + (timeout / sToUs);
wait.tv_nsec = (timeout % sToUs) * 1000U;
wait.tv_sec = tv.tv_sec + (timeoutUsecs / sToUs);
wait.tv_nsec = (timeoutUsecs % sToUs) * 1000U;
err = pthread_cond_timedwait(&m_cond, m_mutex.getPtr(), &wait);
if (err != 0)
{
Expand Down
16 changes: 14 additions & 2 deletions erpc_c/port/erpc_threading_threadx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,21 @@ void Semaphore::put(void)
tx_semaphore_put(&m_sem);
}

bool Semaphore::get(uint32_t timeout)
bool Semaphore::get(uint32_t timeoutUsecs)
{
UINT status = tx_semaphore_get(&m_sem, timeout);
if (timeoutUsecs != kWaitForever)
{
if (timeoutUsecs > 0U)
{
timeoutUsecs /= 1000U;
if (timeoutUsecs == 0U)
{
timeoutUsecs = 1U;
}
}
}

UINT status = tx_semaphore_get(&m_sem, timeoutUsecs);
return (status == TX_SUCCESS);
}

Expand Down
16 changes: 14 additions & 2 deletions erpc_c/port/erpc_threading_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,21 @@ void Semaphore::put(void)
m_mutex.unlock();
}

bool Semaphore::get(uint32_t timeout)
bool Semaphore::get(uint32_t timeoutUsecs)
{
DWORD ret = WaitForSingleObject(m_sem, timeout);
if (timeoutUsecs != kWaitForever)
{
if (timeoutUsecs > 0U)
{
timeoutUsecs /= 1000U;
if (timeoutUsecs == 0U)
{
timeoutUsecs = 1U;
}
}
}

DWORD ret = WaitForSingleObject(m_sem, timeoutUsecs);
m_mutex.lock();
--m_count;
m_mutex.unlock();
Expand Down
16 changes: 14 additions & 2 deletions erpc_c/port/erpc_threading_zephyr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,21 @@ void Semaphore::put(void)
k_sem_give(&m_sem);
}

bool Semaphore::get(uint32_t timeout)
bool Semaphore::get(uint32_t timeoutUsecs)
{
return (k_sem_take(&m_sem, timeout / 1000) == 0);
if (timeoutUsecs != kWaitForever)
{
if (timeoutUsecs > 0U)
{
timeoutUsecs /= 1000U;
if (timeoutUsecs == 0U)
{
timeoutUsecs = 1U;
}
}
}

return (k_sem_take(&m_sem, timeoutUsecs) == 0);
}

int Semaphore::getCount(void) const
Expand Down