Merge pull request #14497 from jarlamsa/no_duplicate_status_cb

Check for duplicate status callbacks before adding to the list
pull/14655/head
Martin Kojtal 2021-05-11 11:41:06 +02:00 committed by GitHub
commit 125f58449d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -145,6 +145,13 @@ static void call_all_event_listeners(NetworkInterface *iface, nsapi_event_t even
void NetworkInterface::add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) void NetworkInterface::add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
{ {
iface_eventlist_t *event_list = get_interface_event_list_head(); iface_eventlist_t *event_list = get_interface_event_list_head();
#if MBED_CONF_PLATFORM_CALLBACK_COMPARABLE
ns_list_foreach_safe(iface_eventlist_entry_t, entry, event_list) {
if (entry->status_cb == status_cb && entry->iface == this) {
return;
}
}
#endif
iface_eventlist_entry_t *entry = new iface_eventlist_entry_t; iface_eventlist_entry_t *entry = new iface_eventlist_entry_t;
entry->iface = this; entry->iface = this;
entry->status_cb = status_cb; entry->status_cb = status_cb;
@ -160,7 +167,6 @@ void NetworkInterface::remove_event_listener(mbed::Callback<void(nsapi_event_t,
if (entry->status_cb == status_cb && entry->iface == this) { if (entry->status_cb == status_cb && entry->iface == this) {
ns_list_remove(event_list, entry); ns_list_remove(event_list, entry);
delete entry; delete entry;
return;
} }
} }
} }