mirror of
https://github.com/espressif/esp-idf
synced 2025-03-09 17:19:09 -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.
|
* 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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -19,21 +19,21 @@
|
|||||||
#include "esp_wifi_driver.h"
|
#include "esp_wifi_driver.h"
|
||||||
|
|
||||||
struct eloop_timeout {
|
struct eloop_timeout {
|
||||||
struct dl_list list;
|
struct dl_list list;
|
||||||
struct os_reltime time;
|
struct os_reltime time;
|
||||||
void *eloop_data;
|
void *eloop_data;
|
||||||
void *user_data;
|
void *user_data;
|
||||||
eloop_timeout_handler handler;
|
eloop_timeout_handler handler;
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
char func_name[100];
|
char func_name[100];
|
||||||
int line;
|
int line;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct eloop_data {
|
struct eloop_data {
|
||||||
struct dl_list timeout;
|
struct dl_list timeout;
|
||||||
ETSTimer eloop_timer;
|
ETSTimer eloop_timer;
|
||||||
bool eloop_started;
|
bool eloop_started;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ELOOP_LOCK() os_mutex_lock(eloop_data_lock)
|
#define ELOOP_LOCK() os_mutex_lock(eloop_data_lock)
|
||||||
@ -45,364 +45,368 @@ static struct eloop_data eloop;
|
|||||||
|
|
||||||
static int eloop_run_wrapper(void *data)
|
static int eloop_run_wrapper(void *data)
|
||||||
{
|
{
|
||||||
eloop_run();
|
eloop_run();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eloop_run_timer(void *args)
|
static void eloop_run_timer(void *args)
|
||||||
{
|
{
|
||||||
/* Execute timers in pptask context to make it thread safe */
|
/* Execute timers in pptask context to make it thread safe */
|
||||||
wifi_ipc_config_t cfg;
|
wifi_ipc_config_t cfg;
|
||||||
|
|
||||||
cfg.fn = eloop_run_wrapper;
|
cfg.fn = eloop_run_wrapper;
|
||||||
cfg.arg = NULL;
|
cfg.arg = NULL;
|
||||||
cfg.arg_size = 0;
|
cfg.arg_size = 0;
|
||||||
esp_wifi_ipc_internal(&cfg, false);
|
esp_wifi_ipc_internal(&cfg, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int eloop_init(void)
|
int eloop_init(void)
|
||||||
{
|
{
|
||||||
os_memset(&eloop, 0, sizeof(eloop));
|
os_memset(&eloop, 0, sizeof(eloop));
|
||||||
dl_list_init(&eloop.timeout);
|
dl_list_init(&eloop.timeout);
|
||||||
os_timer_disarm(&eloop.eloop_timer);
|
os_timer_disarm(&eloop.eloop_timer);
|
||||||
os_timer_setfn(&eloop.eloop_timer, (ETSTimerFunc *)eloop_run_timer, NULL);
|
os_timer_setfn(&eloop.eloop_timer, (ETSTimerFunc *)eloop_run_timer, NULL);
|
||||||
|
|
||||||
eloop_data_lock = os_recursive_mutex_create();
|
eloop_data_lock = os_recursive_mutex_create();
|
||||||
|
|
||||||
if (!eloop_data_lock) {
|
if (!eloop_data_lock) {
|
||||||
wpa_printf(MSG_ERROR, "failed to create eloop data loop");
|
wpa_printf(MSG_ERROR, "failed to create eloop data loop");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
eloop.eloop_started = true;
|
eloop.eloop_started = true;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
int eloop_register_timeout_debug(unsigned int secs, unsigned int usecs,
|
int eloop_register_timeout_debug(unsigned int secs, unsigned int usecs,
|
||||||
eloop_timeout_handler handler, void *eloop_data,
|
eloop_timeout_handler handler, void *eloop_data,
|
||||||
void *user_data, const char *func, int line)
|
void *user_data, const char *func, int line)
|
||||||
#else
|
#else
|
||||||
int eloop_register_timeout(unsigned int secs, unsigned int usecs,
|
int eloop_register_timeout(unsigned int secs, unsigned int usecs,
|
||||||
eloop_timeout_handler handler,
|
eloop_timeout_handler handler,
|
||||||
void *eloop_data, void *user_data)
|
void *eloop_data, void *user_data)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
struct eloop_timeout *timeout, *tmp;
|
struct eloop_timeout *timeout, *tmp;
|
||||||
os_time_t now_sec;
|
os_time_t now_sec;
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
int count = 0;
|
int count = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
timeout = os_zalloc(sizeof(*timeout));
|
timeout = os_zalloc(sizeof(*timeout));
|
||||||
if (timeout == NULL)
|
if (timeout == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
if (os_get_reltime(&timeout->time) < 0) {
|
}
|
||||||
os_free(timeout);
|
if (os_get_reltime(&timeout->time) < 0) {
|
||||||
return -1;
|
os_free(timeout);
|
||||||
}
|
return -1;
|
||||||
now_sec = timeout->time.sec;
|
}
|
||||||
timeout->time.sec += secs;
|
now_sec = timeout->time.sec;
|
||||||
if (timeout->time.sec < now_sec)
|
timeout->time.sec += secs;
|
||||||
goto overflow;
|
if (timeout->time.sec < now_sec) {
|
||||||
timeout->time.usec += usecs;
|
goto overflow;
|
||||||
while (timeout->time.usec >= 1000000) {
|
}
|
||||||
timeout->time.sec++;
|
timeout->time.usec += usecs;
|
||||||
timeout->time.usec -= 1000000;
|
while (timeout->time.usec >= 1000000) {
|
||||||
}
|
timeout->time.sec++;
|
||||||
if (timeout->time.sec < now_sec)
|
timeout->time.usec -= 1000000;
|
||||||
goto overflow;
|
}
|
||||||
timeout->eloop_data = eloop_data;
|
if (timeout->time.sec < now_sec) {
|
||||||
timeout->user_data = user_data;
|
goto overflow;
|
||||||
timeout->handler = handler;
|
}
|
||||||
|
timeout->eloop_data = eloop_data;
|
||||||
|
timeout->user_data = user_data;
|
||||||
|
timeout->handler = handler;
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
os_strlcpy(timeout->func_name, func, 100);
|
os_strlcpy(timeout->func_name, func, 100);
|
||||||
timeout->line = line;
|
timeout->line = line;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Maintain timeouts in order of increasing time */
|
/* Maintain timeouts in order of increasing time */
|
||||||
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
||||||
if (os_reltime_before(&timeout->time, &tmp->time)) {
|
if (os_reltime_before(&timeout->time, &tmp->time)) {
|
||||||
ELOOP_LOCK();
|
ELOOP_LOCK();
|
||||||
dl_list_add(tmp->list.prev, &timeout->list);
|
dl_list_add(tmp->list.prev, &timeout->list);
|
||||||
ELOOP_UNLOCK();
|
ELOOP_UNLOCK();
|
||||||
goto run;
|
goto run;
|
||||||
}
|
}
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
count++;
|
count++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
ELOOP_LOCK();
|
ELOOP_LOCK();
|
||||||
dl_list_add_tail(&eloop.timeout, &timeout->list);
|
dl_list_add_tail(&eloop.timeout, &timeout->list);
|
||||||
ELOOP_UNLOCK();
|
ELOOP_UNLOCK();
|
||||||
|
|
||||||
run:
|
run:
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
wpa_printf(MSG_DEBUG, "ELOOP: Added one timer from %s:%d to call %p, current order=%d",
|
wpa_printf(MSG_DEBUG, "ELOOP: Added one timer from %s:%d to call %p, current order=%d",
|
||||||
timeout->func_name, line, timeout->handler, count);
|
timeout->func_name, line, timeout->handler, count);
|
||||||
#endif
|
#endif
|
||||||
ELOOP_LOCK();
|
ELOOP_LOCK();
|
||||||
os_timer_disarm(&eloop.eloop_timer);
|
os_timer_disarm(&eloop.eloop_timer);
|
||||||
os_timer_arm(&eloop.eloop_timer, 0, 0);
|
os_timer_arm(&eloop.eloop_timer, 0, 0);
|
||||||
ELOOP_UNLOCK();
|
ELOOP_UNLOCK();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
overflow:
|
overflow:
|
||||||
/*
|
/*
|
||||||
* Integer overflow - assume long enough timeout to be assumed
|
* Integer overflow - assume long enough timeout to be assumed
|
||||||
* to be infinite, i.e., the timeout would never happen.
|
* to be infinite, i.e., the timeout would never happen.
|
||||||
*/
|
*/
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
"ELOOP: Too long timeout (secs=%u usecs=%u) to ever happen - ignore it",
|
"ELOOP: Too long timeout (secs=%u usecs=%u) to ever happen - ignore it",
|
||||||
secs,usecs);
|
secs, usecs);
|
||||||
os_free(timeout);
|
os_free(timeout);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool timeout_exists(struct eloop_timeout *old)
|
static bool timeout_exists(struct eloop_timeout *old)
|
||||||
{
|
{
|
||||||
struct eloop_timeout *timeout, *prev;
|
struct eloop_timeout *timeout, *prev;
|
||||||
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
||||||
struct eloop_timeout, list) {
|
struct eloop_timeout, list) {
|
||||||
if (old == timeout)
|
if (old == timeout) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eloop_remove_timeout(struct eloop_timeout *timeout)
|
static void eloop_remove_timeout(struct eloop_timeout *timeout)
|
||||||
{
|
{
|
||||||
bool timeout_present = false;
|
bool timeout_present = false;
|
||||||
ELOOP_LOCK();
|
ELOOP_LOCK();
|
||||||
/* Make sure timeout still exists(Another context may have deleted this) */
|
/* Make sure timeout still exists(Another context may have deleted this) */
|
||||||
timeout_present = timeout_exists(timeout);
|
timeout_present = timeout_exists(timeout);
|
||||||
if (timeout_present)
|
if (timeout_present) {
|
||||||
dl_list_del(&timeout->list);
|
dl_list_del(&timeout->list);
|
||||||
ELOOP_UNLOCK();
|
}
|
||||||
if (timeout_present)
|
ELOOP_UNLOCK();
|
||||||
os_free(timeout);
|
if (timeout_present) {
|
||||||
|
os_free(timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
int eloop_cancel_timeout_debug(eloop_timeout_handler handler, void *eloop_data,
|
int eloop_cancel_timeout_debug(eloop_timeout_handler handler, void *eloop_data,
|
||||||
void *user_data, const char *func, int line)
|
void *user_data, const char *func, int line)
|
||||||
#else
|
#else
|
||||||
int eloop_cancel_timeout(eloop_timeout_handler handler,
|
int eloop_cancel_timeout(eloop_timeout_handler handler,
|
||||||
void *eloop_data, void *user_data)
|
void *eloop_data, void *user_data)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
struct eloop_timeout *timeout, *prev;
|
struct eloop_timeout *timeout, *prev;
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
|
|
||||||
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
||||||
struct eloop_timeout, list) {
|
struct eloop_timeout, list) {
|
||||||
if (timeout->handler == handler &&
|
if (timeout->handler == handler &&
|
||||||
(timeout->eloop_data == eloop_data ||
|
(timeout->eloop_data == eloop_data ||
|
||||||
eloop_data == ELOOP_ALL_CTX) &&
|
eloop_data == ELOOP_ALL_CTX) &&
|
||||||
(timeout->user_data == user_data ||
|
(timeout->user_data == user_data ||
|
||||||
user_data == ELOOP_ALL_CTX)) {
|
user_data == ELOOP_ALL_CTX)) {
|
||||||
eloop_remove_timeout(timeout);
|
eloop_remove_timeout(timeout);
|
||||||
removed++;
|
removed++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
wpa_printf(MSG_DEBUG, "ELOOP: %s:%d called to remove timer handler=%p, removed count=%d",
|
wpa_printf(MSG_DEBUG, "ELOOP: %s:%d called to remove timer handler=%p, removed count=%d",
|
||||||
func, line, handler, removed);
|
func, line, handler, removed);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int eloop_cancel_timeout_one(eloop_timeout_handler handler,
|
int eloop_cancel_timeout_one(eloop_timeout_handler handler,
|
||||||
void *eloop_data, void *user_data,
|
void *eloop_data, void *user_data,
|
||||||
struct os_reltime *remaining)
|
struct os_reltime *remaining)
|
||||||
{
|
{
|
||||||
struct eloop_timeout *timeout, *prev;
|
struct eloop_timeout *timeout, *prev;
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
struct os_reltime now;
|
struct os_reltime now;
|
||||||
|
|
||||||
os_get_reltime(&now);
|
os_get_reltime(&now);
|
||||||
remaining->sec = remaining->usec = 0;
|
remaining->sec = remaining->usec = 0;
|
||||||
|
|
||||||
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
||||||
struct eloop_timeout, list) {
|
struct eloop_timeout, list) {
|
||||||
if (timeout->handler == handler &&
|
if (timeout->handler == handler &&
|
||||||
(timeout->eloop_data == eloop_data) &&
|
(timeout->eloop_data == eloop_data) &&
|
||||||
(timeout->user_data == user_data)) {
|
(timeout->user_data == user_data)) {
|
||||||
removed = 1;
|
removed = 1;
|
||||||
if (os_reltime_before(&now, &timeout->time))
|
if (os_reltime_before(&now, &timeout->time)) {
|
||||||
os_reltime_sub(&timeout->time, &now, remaining);
|
os_reltime_sub(&timeout->time, &now, remaining);
|
||||||
eloop_remove_timeout(timeout);
|
}
|
||||||
break;
|
eloop_remove_timeout(timeout);
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
return removed;
|
}
|
||||||
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int eloop_is_timeout_registered(eloop_timeout_handler handler,
|
int eloop_is_timeout_registered(eloop_timeout_handler handler,
|
||||||
void *eloop_data, void *user_data)
|
void *eloop_data, void *user_data)
|
||||||
{
|
{
|
||||||
struct eloop_timeout *tmp;
|
struct eloop_timeout *tmp;
|
||||||
|
|
||||||
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
||||||
if (tmp->handler == handler &&
|
if (tmp->handler == handler &&
|
||||||
tmp->eloop_data == eloop_data &&
|
tmp->eloop_data == eloop_data &&
|
||||||
tmp->user_data == user_data)
|
tmp->user_data == user_data) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int eloop_deplete_timeout(unsigned int req_secs, unsigned int req_usecs,
|
int eloop_deplete_timeout(unsigned int req_secs, unsigned int req_usecs,
|
||||||
eloop_timeout_handler handler, void *eloop_data,
|
eloop_timeout_handler handler, void *eloop_data,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct os_reltime now, requested, remaining;
|
struct os_reltime now, requested, remaining;
|
||||||
struct eloop_timeout *tmp;
|
struct eloop_timeout *tmp;
|
||||||
|
|
||||||
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
||||||
if (tmp->handler == handler &&
|
if (tmp->handler == handler &&
|
||||||
tmp->eloop_data == eloop_data &&
|
tmp->eloop_data == eloop_data &&
|
||||||
tmp->user_data == user_data) {
|
tmp->user_data == user_data) {
|
||||||
requested.sec = req_secs;
|
requested.sec = req_secs;
|
||||||
requested.usec = req_usecs;
|
requested.usec = req_usecs;
|
||||||
os_get_reltime(&now);
|
os_get_reltime(&now);
|
||||||
os_reltime_sub(&tmp->time, &now, &remaining);
|
os_reltime_sub(&tmp->time, &now, &remaining);
|
||||||
if (os_reltime_before(&requested, &remaining)) {
|
if (os_reltime_before(&requested, &remaining)) {
|
||||||
eloop_cancel_timeout(handler, eloop_data,
|
eloop_cancel_timeout(handler, eloop_data,
|
||||||
user_data);
|
user_data);
|
||||||
eloop_register_timeout(requested.sec,
|
eloop_register_timeout(requested.sec,
|
||||||
requested.usec,
|
requested.usec,
|
||||||
handler, eloop_data,
|
handler, eloop_data,
|
||||||
user_data);
|
user_data);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs,
|
int eloop_replenish_timeout(unsigned int req_secs, unsigned int req_usecs,
|
||||||
eloop_timeout_handler handler, void *eloop_data,
|
eloop_timeout_handler handler, void *eloop_data,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct os_reltime now, requested, remaining;
|
struct os_reltime now, requested, remaining;
|
||||||
struct eloop_timeout *tmp;
|
struct eloop_timeout *tmp;
|
||||||
|
|
||||||
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
|
||||||
if (tmp->handler == handler &&
|
if (tmp->handler == handler &&
|
||||||
tmp->eloop_data == eloop_data &&
|
tmp->eloop_data == eloop_data &&
|
||||||
tmp->user_data == user_data) {
|
tmp->user_data == user_data) {
|
||||||
requested.sec = req_secs;
|
requested.sec = req_secs;
|
||||||
requested.usec = req_usecs;
|
requested.usec = req_usecs;
|
||||||
os_get_reltime(&now);
|
os_get_reltime(&now);
|
||||||
os_reltime_sub(&tmp->time, &now, &remaining);
|
os_reltime_sub(&tmp->time, &now, &remaining);
|
||||||
if (os_reltime_before(&remaining, &requested)) {
|
if (os_reltime_before(&remaining, &requested)) {
|
||||||
eloop_cancel_timeout(handler, eloop_data,
|
eloop_cancel_timeout(handler, eloop_data,
|
||||||
user_data);
|
user_data);
|
||||||
eloop_register_timeout(requested.sec,
|
eloop_register_timeout(requested.sec,
|
||||||
requested.usec,
|
requested.usec,
|
||||||
handler, eloop_data,
|
handler, eloop_data,
|
||||||
user_data);
|
user_data);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eloop_run(void)
|
void eloop_run(void)
|
||||||
{
|
{
|
||||||
struct os_reltime tv, now;
|
struct os_reltime tv, now;
|
||||||
|
|
||||||
while (!dl_list_empty(&eloop.timeout)) {
|
while (!dl_list_empty(&eloop.timeout)) {
|
||||||
struct eloop_timeout *timeout;
|
struct eloop_timeout *timeout;
|
||||||
|
|
||||||
timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
|
timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
|
||||||
list);
|
list);
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
os_get_reltime(&now);
|
os_get_reltime(&now);
|
||||||
if (os_reltime_before(&now, &timeout->time)) {
|
if (os_reltime_before(&now, &timeout->time)) {
|
||||||
/* we don't need to process it rn, do it later */
|
/* we don't need to process it rn, do it later */
|
||||||
uint32_t ms;
|
uint32_t ms;
|
||||||
os_reltime_sub(&timeout->time, &now, &tv);
|
os_reltime_sub(&timeout->time, &now, &tv);
|
||||||
ms = tv.sec * 1000 + tv.usec / 1000;
|
ms = tv.sec * 1000 + tv.usec / 1000;
|
||||||
ELOOP_LOCK();
|
ELOOP_LOCK();
|
||||||
os_timer_disarm(&eloop.eloop_timer);
|
os_timer_disarm(&eloop.eloop_timer);
|
||||||
os_timer_arm(&eloop.eloop_timer, ms, 0);
|
os_timer_arm(&eloop.eloop_timer, ms, 0);
|
||||||
ELOOP_UNLOCK();
|
ELOOP_UNLOCK();
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if some registered timeouts have occurred */
|
/* check if some registered timeouts have occurred */
|
||||||
timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
|
timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
|
||||||
list);
|
list);
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
os_get_reltime(&now);
|
os_get_reltime(&now);
|
||||||
if (!os_reltime_before(&now, &timeout->time)) {
|
if (!os_reltime_before(&now, &timeout->time)) {
|
||||||
void *eloop_data = timeout->eloop_data;
|
void *eloop_data = timeout->eloop_data;
|
||||||
void *user_data = timeout->user_data;
|
void *user_data = timeout->user_data;
|
||||||
eloop_timeout_handler handler =
|
eloop_timeout_handler handler =
|
||||||
timeout->handler;
|
timeout->handler;
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
char fn_name[100] = {0};
|
char fn_name[100] = {0};
|
||||||
int line = timeout->line;
|
int line = timeout->line;
|
||||||
os_strlcpy(fn_name, timeout->func_name, 100);
|
os_strlcpy(fn_name, timeout->func_name, 100);
|
||||||
#endif
|
#endif
|
||||||
eloop_remove_timeout(timeout);
|
eloop_remove_timeout(timeout);
|
||||||
#ifdef ELOOP_DEBUG
|
#ifdef ELOOP_DEBUG
|
||||||
wpa_printf(MSG_DEBUG, "ELOOP: Running timer fn:%p scheduled by %s:%d ",
|
wpa_printf(MSG_DEBUG, "ELOOP: Running timer fn:%p scheduled by %s:%d ",
|
||||||
handler, fn_name, line);
|
handler, fn_name, line);
|
||||||
#endif
|
#endif
|
||||||
handler(eloop_data, user_data);
|
handler(eloop_data, user_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eloop_destroy(void)
|
void eloop_destroy(void)
|
||||||
{
|
{
|
||||||
struct eloop_timeout *timeout, *prev;
|
struct eloop_timeout *timeout, *prev;
|
||||||
struct os_reltime now;
|
struct os_reltime now;
|
||||||
|
|
||||||
if (!eloop.eloop_started) {
|
if (!eloop.eloop_started) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
os_get_reltime(&now);
|
os_get_reltime(&now);
|
||||||
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
dl_list_for_each_safe(timeout, prev, &eloop.timeout,
|
||||||
struct eloop_timeout, list) {
|
struct eloop_timeout, list) {
|
||||||
int sec, usec;
|
int sec, usec;
|
||||||
sec = timeout->time.sec - now.sec;
|
sec = timeout->time.sec - now.sec;
|
||||||
usec = timeout->time.usec - now.usec;
|
usec = timeout->time.usec - now.usec;
|
||||||
if (timeout->time.usec < now.usec) {
|
if (timeout->time.usec < now.usec) {
|
||||||
sec--;
|
sec--;
|
||||||
usec += 1000000;
|
usec += 1000000;
|
||||||
}
|
}
|
||||||
wpa_printf(MSG_INFO, "ELOOP: remaining timeout: %d.%06d "
|
wpa_printf(MSG_INFO, "ELOOP: remaining timeout: %d.%06d "
|
||||||
"eloop_data=%p user_data=%p handler=%p",
|
"eloop_data=%p user_data=%p handler=%p",
|
||||||
sec, usec, timeout->eloop_data, timeout->user_data,
|
sec, usec, timeout->eloop_data, timeout->user_data,
|
||||||
timeout->handler);
|
timeout->handler);
|
||||||
eloop_remove_timeout(timeout);
|
eloop_remove_timeout(timeout);
|
||||||
}
|
}
|
||||||
if (eloop_data_lock) {
|
if (eloop_data_lock) {
|
||||||
os_semphr_delete(eloop_data_lock);
|
os_mutex_delete(eloop_data_lock);
|
||||||
eloop_data_lock = NULL;
|
eloop_data_lock = NULL;
|
||||||
}
|
}
|
||||||
os_timer_disarm(&eloop.eloop_timer);
|
os_timer_disarm(&eloop.eloop_timer);
|
||||||
os_timer_done(&eloop.eloop_timer);
|
os_timer_done(&eloop.eloop_timer);
|
||||||
os_memset(&eloop, 0, sizeof(eloop));
|
os_memset(&eloop, 0, sizeof(eloop));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user