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:
parent
ed280aa81b
commit
e53b9585dd
@ -380,6 +380,17 @@ void dcb_append_readqueue(DCB *dcb, GWBUF *buffer);
|
||||
void dcb_enable_session_timeouts();
|
||||
void dcb_process_idle_sessions(int thr);
|
||||
|
||||
/**
|
||||
* @brief Call a function for each connected DCB
|
||||
*
|
||||
* @param func Function to call. The function should return @c true to continue iteration
|
||||
* and @c false to stop iteration earlier. The first parameter is a DCB and the second
|
||||
* is the value of @c data that the user provided.
|
||||
* @param data User provided data passed as the second parameter to @c func
|
||||
* @return True if all DCBs were iterated, false if the callback returned false
|
||||
*/
|
||||
bool dcb_foreach(bool (*func)(DCB *, void *), void *data);
|
||||
|
||||
/**
|
||||
* DCB flags values
|
||||
*/
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user