Skip to content

Remove Semaphore deprecated APIs #12609

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
Mar 31, 2020
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
4 changes: 2 additions & 2 deletions TESTS/mbed_drivers/timeout/timeout_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ void test_no_wait(void)
Semaphore sem(0, 1);
T timeout;
timeout.attach_callback(mbed::callback(sem_callback, &sem), 0ULL);
int32_t sem_slots = sem.wait(0);
TEST_ASSERT_EQUAL(1, sem_slots);
bool sem_acquired = sem.try_acquire();
TEST_ASSERT_EQUAL(true, sem_acquired);
timeout.detach();
}
}
Expand Down
10 changes: 0 additions & 10 deletions UNITTESTS/stubs/Semaphore_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ void Semaphore::constructor(int32_t count, uint16_t max_count)

}

int32_t Semaphore::wait(uint32_t millisec)
{
return Semaphore_stub::wait_return_value;
}

int32_t Semaphore::wait_until(uint64_t millisec)
{
return Semaphore_stub::wait_return_value;
}

void Semaphore::acquire()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ static bool acl_data_wait(void)

/* Wait 10 sec for previous ACL command to be ack'ed by Low Layers
* before sending the next one */
if (acl_ack_sem.wait(10000) < 1) {
if (!acl_ack_sem.try_acquire_for(10000)) {
return false;
} else {
return true;
Expand All @@ -777,7 +777,7 @@ static void sysevt_received(void *pdata)
static bool sysevt_wait(void)
{
/* Wait for 10sec max - if not return an error */
if (sys_event_sem.wait(10000) < 1) {
if (!sys_event_sem.try_acquire_for(10000)) {
return false;
} else {
/* release immmediately, now that M0 runs */
Expand All @@ -791,7 +791,7 @@ static bool sysevt_wait(void)
static bool sysevt_check(void)
{
/* Check if system is UP and runing already */
if (sys_event_sem.wait(10) < 1) {
if (!sys_event_sem.try_acquire_for(10)) {
return false;
} else {
/* release immmediately as M0 already runs */
Expand Down Expand Up @@ -822,7 +822,7 @@ void shci_cmd_resp_release(uint32_t flag)
void shci_cmd_resp_wait(uint32_t timeout)
{
/* TO DO: manage timeouts if we can return an error */
if (sys_resp_sem.wait(timeout) < 1) {
if (!sys_resp_sem.try_acquire_for(timeout)) {
tr_error("shci_cmd_resp_wait timed out");
}
}
Expand Down
28 changes: 0 additions & 28 deletions rtos/Semaphore.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,6 @@ class Semaphore : private mbed::NonCopyable<Semaphore> {
*/
Semaphore(int32_t count, uint16_t max_count);

/** Wait until a Semaphore resource becomes available.

@deprecated Do not use this function. This function has been replaced with acquire(), try_acquire() and try_acquire_for() functions.

@param millisec timeout value. (default: osWaitForever).
@return number of available tokens, before taking one; or -1 in case of incorrect parameters

@note You may call this function from ISR context if the millisec parameter is set to 0.
*/
MBED_DEPRECATED_SINCE("mbed-os-5.13", "Replaced with acquire, try_acquire() and try_acquire_for() functions")
int32_t wait(uint32_t millisec = osWaitForever);

/** Wait until a Semaphore resource becomes available.

@deprecated Do not use this function. This function has been replaced with try_acquire_until().

@param millisec absolute timeout time, referenced to Kernel::get_ms_count()
@return number of available tokens, before taking one; or -1 in case of incorrect parameters
@note the underlying RTOS may have a limit to the maximum wait time
due to internal 32-bit computations, but this is guaranteed to work if the
wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded,
the acquire attempt will time out earlier than specified.

@note You cannot call this function from ISR context.
*/
MBED_DEPRECATED_SINCE("mbed-os-5.13", "Replaced with try_acquire_until()")
int32_t wait_until(uint64_t millisec);

/** Wait until a Semaphore resource becomes available.

@note You cannot call this function from ISR context.
Expand Down
57 changes: 0 additions & 57 deletions rtos/source/Semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,63 +87,6 @@ bool Semaphore::try_acquire()
#endif
}

#if MBED_CONF_RTOS_PRESENT
/* To sidestep deprecation warnings */
int32_t Semaphore::_wait(uint32_t millisec)
{
osStatus_t stat = osSemaphoreAcquire(_id, millisec);
switch (stat) {
case osOK:
return osSemaphoreGetCount(_id) + 1;
case osErrorTimeout:
case osErrorResource:
return 0;
case osErrorParameter:
default:
return -1;
}
}
#endif

int32_t Semaphore::wait(uint32_t millisec)
{
#if MBED_CONF_RTOS_PRESENT
return _wait(millisec);
#else
sem_wait_capture capture = { this, false };
mbed::internal::do_timed_sleep_relative_or_forever(millisec, semaphore_available, &capture);
if (capture.acquired) {
return core_util_atomic_load_s32(&_count) + 1;
} else {
return 0;
}
#endif
}

int32_t Semaphore::wait_until(uint64_t millisec)
{
#if MBED_CONF_RTOS_PRESENT
uint64_t now = Kernel::get_ms_count();

if (now >= millisec) {
return _wait(0);
} else if (millisec - now >= osWaitForever) {
// API permits early return
return _wait(osWaitForever - 1);
} else {
return _wait(millisec - now);
}
#else
sem_wait_capture capture = { this, false };
mbed::internal::do_timed_sleep_absolute(millisec, semaphore_available, &capture);
if (capture.acquired) {
return core_util_atomic_load_s32(&_count) + 1;
} else {
return 0;
}
#endif
}

void Semaphore::acquire()
{
#if MBED_CONF_RTOS_PRESENT
Expand Down