MXS-1392 Add reference count to MXS_POLL_DATA
The polling mechanism can now optionally be used for managing the lifetime of an object placed into the poll set. If a MXS_POLL_DATA has a non-null 'free', then the reference count of the data will be increased before calling the handler and decreased after. In that case, if the reference count reaches 0, the free function will be called. Note that the reference counts of *all* MXS_POLL_DATAs returned by 'epoll_wait' will be increased before the events are delivered to the handlers individually for each MXS_POLL_DATA, and then once all events have been delivered, the reference count of each MXS_POLL_DATA will be decreased. This ensure that if there are interdependencies between different MXS_POLL_DATAs returned by one call to 'epoll_wait', the case that an MXS_POLL_DATA is deleted before its events have been delivered can be avoided by using the reference count for lifetime management. In subsequent commits, the reference count will be taken into use in the lifetime management of DCBs.
This commit is contained in:
@ -162,6 +162,8 @@ Worker::Worker(int id,
|
||||
, m_shutdown_initiated(false)
|
||||
{
|
||||
MXS_POLL_DATA::handler = &Worker::epoll_instance_handler;
|
||||
MXS_POLL_DATA::free = NULL;
|
||||
MXS_POLL_DATA::refcount = 0;
|
||||
MXS_POLL_DATA::thread.id = id;
|
||||
}
|
||||
|
||||
@ -1139,6 +1141,15 @@ void Worker::poll_waitevents()
|
||||
|
||||
uint64_t cycle_start = hkheartbeat;
|
||||
|
||||
for (int i = 0; i < nfds; i++)
|
||||
{
|
||||
MXS_POLL_DATA *data = (MXS_POLL_DATA*)events[i].data.ptr;
|
||||
if (data->free)
|
||||
{
|
||||
poll_inc_ref(data);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < nfds; i++)
|
||||
{
|
||||
/** Calculate event queue statistics */
|
||||
@ -1200,6 +1211,18 @@ void Worker::poll_waitevents()
|
||||
m_statistics.maxexectime = MXS_MAX(m_statistics.maxexectime, qtime);
|
||||
}
|
||||
|
||||
for (int i = 0; i < nfds; i++)
|
||||
{
|
||||
MXS_POLL_DATA *data = (MXS_POLL_DATA*)events[i].data.ptr;
|
||||
if (data->free)
|
||||
{
|
||||
if (poll_dec_ref(data) == 1)
|
||||
{
|
||||
data->free(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dcb_process_idle_sessions(m_id);
|
||||
|
||||
m_state = ZPROCESSING;
|
||||
|
Reference in New Issue
Block a user