Merge pull request #12609 from rajkan01/semwait_remove_deprecation

Remove Semaphore deprecated APIs
pull/12728/head
Martin Kojtal 2020-03-31 10:36:43 +02:00 committed by GitHub
commit 8b929726e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 101 deletions

View File

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

View File

@ -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()
{

View File

@ -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;
@ -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 */
@ -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 */
@ -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");
}
}

View File

@ -62,34 +62,6 @@ public:
*/
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.

View File

@ -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