Skip to content

Commit 06cfc1a

Browse files
committed
Remove Semaphore deprecated APIs
1 parent fe85cbd commit 06cfc1a

File tree

5 files changed

+6
-101
lines changed

5 files changed

+6
-101
lines changed

TESTS/mbed_drivers/timeout/timeout_tests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ void test_no_wait(void)
201201
Semaphore sem(0, 1);
202202
T timeout;
203203
timeout.attach_callback(mbed::callback(sem_callback, &sem), 0ULL);
204-
int32_t sem_slots = sem.wait(0);
205-
TEST_ASSERT_EQUAL(1, sem_slots);
204+
bool sem_acquired = sem.try_acquire();
205+
TEST_ASSERT_EQUAL(true, sem_acquired);
206206
timeout.detach();
207207
}
208208
}

UNITTESTS/stubs/Semaphore_stub.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ void Semaphore::constructor(int32_t count, uint16_t max_count)
3838

3939
}
4040

41-
int32_t Semaphore::wait(uint32_t millisec)
42-
{
43-
return Semaphore_stub::wait_return_value;
44-
}
45-
46-
int32_t Semaphore::wait_until(uint64_t millisec)
47-
{
48-
return Semaphore_stub::wait_return_value;
49-
}
50-
5141
void Semaphore::acquire()
5242
{
5343

features/FEATURE_BLE/targets/TARGET_STM/TARGET_STM32WB/HCIDriver.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ static bool acl_data_wait(void)
757757

758758
/* Wait 10 sec for previous ACL command to be ack'ed by Low Layers
759759
* before sending the next one */
760-
if (acl_ack_sem.wait(10000) < 1) {
760+
if (!acl_ack_sem.try_acquire_for(10000)) {
761761
return false;
762762
} else {
763763
return true;
@@ -777,7 +777,7 @@ static void sysevt_received(void *pdata)
777777
static bool sysevt_wait(void)
778778
{
779779
/* Wait for 10sec max - if not return an error */
780-
if (sys_event_sem.wait(10000) < 1) {
780+
if (!sys_event_sem.try_acquire_for(10000)) {
781781
return false;
782782
} else {
783783
/* release immmediately, now that M0 runs */
@@ -791,7 +791,7 @@ static bool sysevt_wait(void)
791791
static bool sysevt_check(void)
792792
{
793793
/* Check if system is UP and runing already */
794-
if (sys_event_sem.wait(10) < 1) {
794+
if (!sys_event_sem.try_acquire_for(10)) {
795795
return false;
796796
} else {
797797
/* release immmediately as M0 already runs */
@@ -822,7 +822,7 @@ void shci_cmd_resp_release(uint32_t flag)
822822
void shci_cmd_resp_wait(uint32_t timeout)
823823
{
824824
/* TO DO: manage timeouts if we can return an error */
825-
if (sys_resp_sem.wait(timeout) < 1) {
825+
if (!sys_resp_sem.try_acquire_for(timeout)) {
826826
tr_error("shci_cmd_resp_wait timed out");
827827
}
828828
}

rtos/Semaphore.h

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,34 +62,6 @@ class Semaphore : private mbed::NonCopyable<Semaphore> {
6262
*/
6363
Semaphore(int32_t count, uint16_t max_count);
6464

65-
/** Wait until a Semaphore resource becomes available.
66-
67-
@deprecated Do not use this function. This function has been replaced with acquire(), try_acquire() and try_acquire_for() functions.
68-
69-
@param millisec timeout value. (default: osWaitForever).
70-
@return number of available tokens, before taking one; or -1 in case of incorrect parameters
71-
72-
@note You may call this function from ISR context if the millisec parameter is set to 0.
73-
*/
74-
MBED_DEPRECATED_SINCE("mbed-os-5.13", "Replaced with acquire, try_acquire() and try_acquire_for() functions")
75-
int32_t wait(uint32_t millisec = osWaitForever);
76-
77-
/** Wait until a Semaphore resource becomes available.
78-
79-
@deprecated Do not use this function. This function has been replaced with try_acquire_until().
80-
81-
@param millisec absolute timeout time, referenced to Kernel::get_ms_count()
82-
@return number of available tokens, before taking one; or -1 in case of incorrect parameters
83-
@note the underlying RTOS may have a limit to the maximum wait time
84-
due to internal 32-bit computations, but this is guaranteed to work if the
85-
wait is <= 0x7fffffff milliseconds (~24 days). If the limit is exceeded,
86-
the acquire attempt will time out earlier than specified.
87-
88-
@note You cannot call this function from ISR context.
89-
*/
90-
MBED_DEPRECATED_SINCE("mbed-os-5.13", "Replaced with try_acquire_until()")
91-
int32_t wait_until(uint64_t millisec);
92-
9365
/** Wait until a Semaphore resource becomes available.
9466
9567
@note You cannot call this function from ISR context.

rtos/source/Semaphore.cpp

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -87,63 +87,6 @@ bool Semaphore::try_acquire()
8787
#endif
8888
}
8989

90-
#if MBED_CONF_RTOS_PRESENT
91-
/* To sidestep deprecation warnings */
92-
int32_t Semaphore::_wait(uint32_t millisec)
93-
{
94-
osStatus_t stat = osSemaphoreAcquire(_id, millisec);
95-
switch (stat) {
96-
case osOK:
97-
return osSemaphoreGetCount(_id) + 1;
98-
case osErrorTimeout:
99-
case osErrorResource:
100-
return 0;
101-
case osErrorParameter:
102-
default:
103-
return -1;
104-
}
105-
}
106-
#endif
107-
108-
int32_t Semaphore::wait(uint32_t millisec)
109-
{
110-
#if MBED_CONF_RTOS_PRESENT
111-
return _wait(millisec);
112-
#else
113-
sem_wait_capture capture = { this, false };
114-
mbed::internal::do_timed_sleep_relative_or_forever(millisec, semaphore_available, &capture);
115-
if (capture.acquired) {
116-
return core_util_atomic_load_s32(&_count) + 1;
117-
} else {
118-
return 0;
119-
}
120-
#endif
121-
}
122-
123-
int32_t Semaphore::wait_until(uint64_t millisec)
124-
{
125-
#if MBED_CONF_RTOS_PRESENT
126-
uint64_t now = Kernel::get_ms_count();
127-
128-
if (now >= millisec) {
129-
return _wait(0);
130-
} else if (millisec - now >= osWaitForever) {
131-
// API permits early return
132-
return _wait(osWaitForever - 1);
133-
} else {
134-
return _wait(millisec - now);
135-
}
136-
#else
137-
sem_wait_capture capture = { this, false };
138-
mbed::internal::do_timed_sleep_absolute(millisec, semaphore_available, &capture);
139-
if (capture.acquired) {
140-
return core_util_atomic_load_s32(&_count) + 1;
141-
} else {
142-
return 0;
143-
}
144-
#endif
145-
}
146-
14790
void Semaphore::acquire()
14891
{
14992
#if MBED_CONF_RTOS_PRESENT

0 commit comments

Comments
 (0)