mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
fix(wpa_supplicant): Add few fixes in eloop task
This commit is contained in:
parent
35e96b977b
commit
c5892a4c96
@ -6,7 +6,7 @@
|
||||
* See README for more details.
|
||||
*/
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@ -95,23 +95,26 @@ int eloop_register_timeout(unsigned int secs, unsigned int usecs,
|
||||
#endif
|
||||
|
||||
timeout = os_zalloc(sizeof(*timeout));
|
||||
if (timeout == NULL)
|
||||
if (timeout == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (os_get_reltime(&timeout->time) < 0) {
|
||||
os_free(timeout);
|
||||
return -1;
|
||||
}
|
||||
now_sec = timeout->time.sec;
|
||||
timeout->time.sec += secs;
|
||||
if (timeout->time.sec < now_sec)
|
||||
if (timeout->time.sec < now_sec) {
|
||||
goto overflow;
|
||||
}
|
||||
timeout->time.usec += usecs;
|
||||
while (timeout->time.usec >= 1000000) {
|
||||
timeout->time.sec++;
|
||||
timeout->time.usec -= 1000000;
|
||||
}
|
||||
if (timeout->time.sec < now_sec)
|
||||
if (timeout->time.sec < now_sec) {
|
||||
goto overflow;
|
||||
}
|
||||
timeout->eloop_data = eloop_data;
|
||||
timeout->user_data = user_data;
|
||||
timeout->handler = handler;
|
||||
@ -165,9 +168,10 @@ static bool timeout_exists(struct eloop_timeout *old)
|
||||
struct eloop_timeout *timeout, *prev;
|
||||
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
||||
struct eloop_timeout, list) {
|
||||
if (old == timeout)
|
||||
if (old == timeout) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -178,12 +182,14 @@ static void eloop_remove_timeout(struct eloop_timeout *timeout)
|
||||
ELOOP_LOCK();
|
||||
/* Make sure timeout still exists(Another context may have deleted this) */
|
||||
timeout_present = timeout_exists(timeout);
|
||||
if (timeout_present)
|
||||
if (timeout_present) {
|
||||
dl_list_del(&timeout->list);
|
||||
}
|
||||
ELOOP_UNLOCK();
|
||||
if (timeout_present)
|
||||
if (timeout_present) {
|
||||
os_free(timeout);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ELOOP_DEBUG
|
||||
int eloop_cancel_timeout_debug(eloop_timeout_handler handler, void *eloop_data,
|
||||
@ -215,7 +221,6 @@ int eloop_cancel_timeout(eloop_timeout_handler handler,
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
int eloop_cancel_timeout_one(eloop_timeout_handler handler,
|
||||
void *eloop_data, void *user_data,
|
||||
struct os_reltime *remaining)
|
||||
@ -233,8 +238,9 @@ int eloop_cancel_timeout_one(eloop_timeout_handler handler,
|
||||
(timeout->eloop_data == eloop_data) &&
|
||||
(timeout->user_data == user_data)) {
|
||||
removed = 1;
|
||||
if (os_reltime_before(&now, &timeout->time))
|
||||
if (os_reltime_before(&now, &timeout->time)) {
|
||||
os_reltime_sub(&timeout->time, &now, remaining);
|
||||
}
|
||||
eloop_remove_timeout(timeout);
|
||||
break;
|
||||
}
|
||||
@ -242,7 +248,6 @@ int eloop_cancel_timeout_one(eloop_timeout_handler handler,
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
int eloop_is_timeout_registered(eloop_timeout_handler handler,
|
||||
void *eloop_data, void *user_data)
|
||||
{
|
||||
@ -251,14 +256,14 @@ int eloop_is_timeout_registered(eloop_timeout_handler handler,
|
||||
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
||||
if (tmp->handler == handler &&
|
||||
tmp->eloop_data == eloop_data &&
|
||||
tmp->user_data == user_data)
|
||||
tmp->user_data == user_data) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int eloop_deplete_timeout(unsigned int req_secs, unsigned int req_usecs,
|
||||
eloop_timeout_handler handler, void *eloop_data,
|
||||
void *user_data)
|
||||
@ -290,7 +295,6 @@ int eloop_deplete_timeout(unsigned int req_secs, unsigned int req_usecs,
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs,
|
||||
eloop_timeout_handler handler, void *eloop_data,
|
||||
void *user_data)
|
||||
@ -399,7 +403,7 @@ void eloop_destroy(void)
|
||||
eloop_remove_timeout(timeout);
|
||||
}
|
||||
if (eloop_data_lock) {
|
||||
os_semphr_delete(eloop_data_lock);
|
||||
os_mutex_delete(eloop_data_lock);
|
||||
eloop_data_lock = NULL;
|
||||
}
|
||||
os_timer_disarm(&eloop.eloop_timer);
|
||||
|
Loading…
Reference in New Issue
Block a user