1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

Kernel: Avoid unnecessary allocations in NetworkAdapter::for_each

This avoids allocations for initializing the Function<T>
for the NetworkAdapter::for_each callback argument.

Applying this patch decreases CPU utilization for NetworkTask
from 40% to 28% when receiving TCP packets at a rate of 100Mbit/s.
This commit is contained in:
Gunnar Beutner 2021-05-12 17:27:37 +02:00 committed by Andreas Kling
parent 76deda802d
commit 1bb20a255f
2 changed files with 11 additions and 9 deletions

View file

@ -21,18 +21,11 @@ namespace Kernel {
static AK::Singleton<Lockable<HashTable<NetworkAdapter*>>> s_table;
static Lockable<HashTable<NetworkAdapter*>>& all_adapters()
Lockable<HashTable<NetworkAdapter*>>& NetworkAdapter::all_adapters()
{
return *s_table;
}
void NetworkAdapter::for_each(Function<void(NetworkAdapter&)> callback)
{
Locker locker(all_adapters().lock());
for (auto& it : all_adapters().resource())
callback(*it);
}
RefPtr<NetworkAdapter> NetworkAdapter::from_ipv4_address(const IPv4Address& address)
{
Locker locker(all_adapters().lock());