Move thread related members of DCB into a substructure

The `thread` structure of a DCB now contains all the members that relate
to thread ownership of the DCB.
This commit is contained in:
Markus Makela
2016-11-23 09:03:50 +02:00
parent 2efa862944
commit 43f248927e
4 changed files with 33 additions and 30 deletions

View File

@ -1660,7 +1660,7 @@ dcb_close(DCB *dcb)
/*<
* Add closing dcb to the top of the list, setting zombie marker
*/
int owner = dcb->owner;
int owner = dcb->thread.id;
dcb->dcb_is_zombie = true;
dcb->memdata.next = zombies[owner];
zombies[owner] = dcb;
@ -3417,20 +3417,20 @@ void dcb_append_readqueue(DCB *dcb, GWBUF *buffer)
void dcb_add_to_list(DCB *dcb)
{
spinlock_acquire(&all_dcbs_lock[dcb->owner]);
spinlock_acquire(&all_dcbs_lock[dcb->thread.id]);
if (all_dcbs[dcb->owner] == NULL)
if (all_dcbs[dcb->thread.id] == NULL)
{
all_dcbs[dcb->owner] = dcb;
all_dcbs[dcb->owner]->thr_tail = dcb;
all_dcbs[dcb->thread.id] = dcb;
all_dcbs[dcb->thread.id]->thread.tail = dcb;
}
else
{
all_dcbs[dcb->owner]->thr_tail->thr_next = dcb;
all_dcbs[dcb->owner]->thr_tail = dcb;
all_dcbs[dcb->thread.id]->thread.tail->thread.next = dcb;
all_dcbs[dcb->thread.id]->thread.tail = dcb;
}
spinlock_release(&all_dcbs_lock[dcb->owner]);
spinlock_release(&all_dcbs_lock[dcb->thread.id]);
}
/**
@ -3440,36 +3440,36 @@ void dcb_add_to_list(DCB *dcb)
*/
static void dcb_remove_from_list(DCB *dcb)
{
spinlock_acquire(&all_dcbs_lock[dcb->owner]);
spinlock_acquire(&all_dcbs_lock[dcb->thread.id]);
if (dcb == all_dcbs[dcb->owner])
if (dcb == all_dcbs[dcb->thread.id])
{
DCB *tail = all_dcbs[dcb->owner]->thr_tail;
all_dcbs[dcb->owner] = all_dcbs[dcb->owner]->thr_next;
all_dcbs[dcb->owner]->thr_tail = tail;
DCB *tail = all_dcbs[dcb->thread.id]->thread.tail;
all_dcbs[dcb->thread.id] = all_dcbs[dcb->thread.id]->thread.next;
all_dcbs[dcb->thread.id]->thread.tail = tail;
}
else
{
DCB *current = all_dcbs[dcb->owner]->thr_next;
DCB *prev = all_dcbs[dcb->owner];
DCB *current = all_dcbs[dcb->thread.id]->thread.next;
DCB *prev = all_dcbs[dcb->thread.id];
while (current)
{
if (current == dcb)
{
if (current == all_dcbs[dcb->owner]->thr_tail)
if (current == all_dcbs[dcb->thread.id]->thread.tail)
{
all_dcbs[dcb->owner]->thr_tail = prev;
all_dcbs[dcb->thread.id]->thread.tail = prev;
}
prev->thr_next = current->thr_next;
prev->thread.next = current->thread.next;
break;
}
prev = current;
current = current->thr_next;
current = current->thread.next;
}
}
spinlock_release(&all_dcbs_lock[dcb->owner]);
spinlock_release(&all_dcbs_lock[dcb->thread.id]);
}
/**

View File

@ -375,14 +375,14 @@ poll_add_dcb(DCB *dcb)
if (dcb->dcb_role == DCB_ROLE_BACKEND_HANDLER)
{
owner = dcb->session->client_dcb->owner;
owner = dcb->session->client_dcb->thread.id;
}
else
{
owner = (unsigned int)atomic_add(&next_epoll_fd, 1) % n_threads;
}
dcb->owner = owner;
dcb->thread.id = owner;
spinlock_release(&dcb->dcb_initlock);
dcb_add_to_list(dcb);
@ -495,7 +495,7 @@ poll_remove_dcb(DCB *dcb)
}
else
{
rc = epoll_ctl(epoll_fd[dcb->owner], EPOLL_CTL_DEL, dcbfd, &ev);
rc = epoll_ctl(epoll_fd[dcb->thread.id], EPOLL_CTL_DEL, dcbfd, &ev);
}
/**
* The poll_resolve_error function will always
@ -885,7 +885,7 @@ process_pollq(int thread_id, struct epoll_event *event)
unsigned long qtime;
DCB *dcb = event->data.ptr;
ss_dassert(dcb->owner == thread_id || dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER);
ss_dassert(dcb->thread.id == thread_id || dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER);
#if PROFILE_POLL
memlog_log(plog, hkheartbeat - dcb->evq.inserted);
#endif
@ -1490,7 +1490,7 @@ static void poll_add_event_to_dcb(DCB* dcb,
event->next = NULL;
event->tail = event;
int thr = dcb->owner;
int thr = dcb->thread.id;
/** It is possible that a housekeeper or a monitor thread inserts a fake
* event into the thread's event queue which is why the operation needs

View File

@ -290,7 +290,7 @@ session_link_dcb(SESSION *session, DCB *dcb)
atomic_add(&session->refcount, 1);
dcb->session = session;
/** Move this DCB under the same thread */
dcb->owner = session->client_dcb->owner;
dcb->thread.id = session->client_dcb->thread.id;
spinlock_release(&session->ses_lock);
return true;
}