Add mapping function for DCBs

The dcb_foreach allows a function to be mapped to all DCBs in
MaxScale. This allows the list of DCBs to be iterated in a safe manner
without having to worry about internal locking of the DCB mechanism.
This commit is contained in:
Markus Makela
2016-11-22 10:55:03 +02:00
parent ed280aa81b
commit e53b9585dd
2 changed files with 35 additions and 0 deletions

View File

@ -3522,3 +3522,27 @@ void dcb_process_idle_sessions(int thr)
}
}
}
bool dcb_foreach(bool(*func)(DCB *, void *), void *data)
{
int nthr = config_threadcount();
bool more = true;
for (int i = 0; i < nthr && more; i++)
{
spinlock_acquire(&all_dcbs_lock[i]);
for (DCB *dcb = all_dcbs[i]; dcb && more; dcb = dcb->memdata.next)
{
if (!func(dcb, data))
{
more = false;
}
}
spinlock_release(&all_dcbs_lock[i]);
}
return more;
}