Skip to content
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

Change Mutex lock and unlock APIs return value to void #12598

Merged
merged 2 commits into from
Mar 11, 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
22 changes: 2 additions & 20 deletions rtos/Mutex.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,9 @@ class Mutex : private mbed::NonCopyable<Mutex> {
/**
Wait until a Mutex becomes available.

@return status code that indicates the execution status of the function:
@a osOK the mutex has been obtained.

@note You cannot call this function from ISR context.
@note This function treats RTOS errors as fatal system errors, so it can only return osOK.
Use of the return value is deprecated, as the return is expected to become void in the future.
*/
#if MBED_CONF_RTOS_PRESENT
osStatus lock();
#else
void lock(); // Value return backwards compatibility not required for non-RTOS
#endif
void lock();

/** Try to lock the mutex, and return immediately
@return true if the mutex was acquired, false otherwise.
Expand Down Expand Up @@ -132,18 +123,9 @@ class Mutex : private mbed::NonCopyable<Mutex> {
/**
Unlock the mutex that has previously been locked by the same thread

@return status code that indicates the execution status of the function:
@a osOK the mutex has been released.

@note You cannot call this function from ISR context.
@note This function treats RTOS errors as fatal system errors, so it can only return osOK.
Use of the return value is deprecated, as the return is expected to become void in the future.
*/
#if MBED_CONF_RTOS_PRESENT
osStatus unlock();
#else
void unlock(); // Value return backwards compatibility not required for non-RTOS
#endif
void unlock();

/** Get the owner the this mutex
@return the current owner of this mutex.
Expand Down
8 changes: 2 additions & 6 deletions rtos/source/Mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void Mutex::constructor(const char *name)
MBED_ASSERT(_id || mbed_get_error_in_progress());
}

osStatus Mutex::lock(void)
void Mutex::lock(void)
{
osStatus status = osMutexAcquire(_id, osWaitForever);
if (osOK == status) {
Expand All @@ -67,8 +67,6 @@ osStatus Mutex::lock(void)
if (status != osOK && !mbed_get_error_in_progress()) {
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_MUTEX_LOCK_FAILED), "Mutex lock failed", status);
}

return osOK;
}

bool Mutex::trylock()
Expand Down Expand Up @@ -109,7 +107,7 @@ bool Mutex::trylock_until(uint64_t millisec)
}
}

osStatus Mutex::unlock()
void Mutex::unlock()
{
osStatus status = osMutexRelease(_id);
if (osOK == status) {
Expand All @@ -119,8 +117,6 @@ osStatus Mutex::unlock()
if (status != osOK && !mbed_get_error_in_progress()) {
MBED_ERROR1(MBED_MAKE_ERROR(MBED_MODULE_KERNEL, MBED_ERROR_CODE_MUTEX_UNLOCK_FAILED), "Mutex unlock failed", status);
}

return status;
}

osThreadId Mutex::get_owner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,13 @@ nsapi_error_t OdinWiFiInterface::set_credentials(const char *ssid, const char *p
return NSAPI_ERROR_PARAMETER;
}

osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);
_mutex.lock();

strncpy(_sta.ssid, ssid, cbWLAN_SSID_MAX_LENGTH);
strncpy(_sta.passwd, pass, cbWLAN_MAX_PASSPHRASE_LENGTH);
_sta.security = security;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return NSAPI_ERROR_OK;
}
Expand Down Expand Up @@ -275,26 +273,18 @@ nsapi_error_t OdinWiFiInterface::set_channel(uint8_t channel)
return NSAPI_ERROR_PARAMETER;
}

osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);

_mutex.lock();
_sta.channel = channel;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return NSAPI_ERROR_OK;
}

nsapi_error_t OdinWiFiInterface::set_timeout(int ms)
{
osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);

_mutex.lock();
_sta.timeout_ms = ms;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return NSAPI_ERROR_OK;
}
Expand Down Expand Up @@ -560,8 +550,7 @@ nsapi_error_t OdinWiFiInterface::set_ap_network(const char *ip_address, const ch
{
nsapi_error_t result = NSAPI_ERROR_PARAMETER;

osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);
_mutex.lock();

if ((ip_address != NULL) && (netmask != NULL) && (gateway != NULL))
{
Expand All @@ -583,8 +572,7 @@ nsapi_error_t OdinWiFiInterface::set_ap_network(const char *ip_address, const ch
result = NSAPI_ERROR_OK;
}

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return result;
}
Expand All @@ -593,28 +581,22 @@ nsapi_error_t OdinWiFiInterface::set_ap_network(const char *ip_address, const ch
nsapi_error_t OdinWiFiInterface::set_ap_credentials(const char *ssid, const char *pass,
nsapi_security_t security)
{
osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);
_mutex.lock();

_ap.ssid = ssid;
_ap.passwd = pass;
_ap.security = security;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return NSAPI_ERROR_OK;
}

nsapi_error_t OdinWiFiInterface::set_ap_channel(uint8_t channel)
{
osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);

_mutex.lock();
_ap.channel = channel;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return NSAPI_ERROR_OK;
}
Expand All @@ -623,13 +605,9 @@ int OdinWiFiInterface::get_ap_connection_count()
{
int cnt;

osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);

_mutex.lock();
cnt = _ap.cnt_connected;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return cnt;
}
Expand All @@ -641,13 +619,9 @@ int OdinWiFiInterface::get_ap_max_connection_count()

nsapi_error_t OdinWiFiInterface::set_ap_dhcp(bool dhcp)
{
osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);

_mutex.lock();
_ap.use_dhcp = dhcp;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return NSAPI_ERROR_OK;
}
Expand Down Expand Up @@ -739,13 +713,9 @@ nsapi_error_t OdinWiFiInterface::ap_stop()

nsapi_error_t OdinWiFiInterface::set_ap_beacon_interval(uint16_t interval)
{
osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);

_mutex.lock();
_ap.beacon_interval = interval;

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

return NSAPI_ERROR_OK;
}
Expand Down Expand Up @@ -860,8 +830,7 @@ void OdinWiFiInterface::handle_in_msg(void)
struct odin_wifi_msg_s *msg = (odin_wifi_msg_s*)evt.value.p;
MBED_ASSERT(msg != 0);

osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);
_mutex.lock();

switch(msg->type) {
case ODIN_WIFI_MSG_USER_CONNECT:
Expand Down Expand Up @@ -949,8 +918,7 @@ void OdinWiFiInterface::handle_in_msg(void)
break;
}

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();

if(msg != 0) {
_msg_pool->free(msg);
Expand Down Expand Up @@ -1530,8 +1498,7 @@ void OdinWiFiInterface::handle_wlan_status_ap_down()

void OdinWiFiInterface::init(bool debug = false)
{
osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);
_mutex.lock();

// Initialise internal variables
_state = S_NOT_INITIALISED;
Expand Down Expand Up @@ -1595,8 +1562,7 @@ void OdinWiFiInterface::init(bool debug = false)

_thread.start(callback(wlan_callb_s::odin_thread_fcn, this));

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();
}

void OdinWiFiInterface::send_user_response_msg(unsigned int type, nsapi_error_t error_code)
Expand Down Expand Up @@ -1817,14 +1783,12 @@ void OdinWiFiInterface::wlan_scan_indication(cbWLAN_ScanIndicationInfo *scan_inf
MBED_ASSERT(ok == osOK);
}
else {
osStatus res = _mutex.lock();
MBED_ASSERT(res == osOK);
_mutex.lock();

// Add scan result to scan_list
update_scan_list(scan_info);

res = _mutex.unlock();
MBED_ASSERT(res == osOK);
_mutex.unlock();
}
}
else {
Expand Down