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:
parent
2efa862944
commit
43f248927e
@ -225,7 +225,6 @@ typedef struct dcb
|
||||
DCBEVENTQ evq; /**< The event queue for this DCB */
|
||||
int fd; /**< The descriptor */
|
||||
dcb_state_t state; /**< Current descriptor state */
|
||||
int owner; /**< Owning thread */
|
||||
SSL_STATE ssl_state; /**< Current state of SSL if in use */
|
||||
int flags; /**< DCB flags */
|
||||
char *remote; /**< Address of remote end */
|
||||
@ -276,8 +275,12 @@ typedef struct dcb
|
||||
bool ssl_write_want_write; /*< Flag */
|
||||
int dcb_port; /**< port of target server */
|
||||
bool was_persistent; /**< Whether this DCB was in the persistent pool */
|
||||
struct dcb *thr_next; /**< Next DCB in owning thread's list */
|
||||
struct dcb *thr_tail; /**< Last DCB in owning thread's list */
|
||||
struct
|
||||
{
|
||||
int id; /**< The owning thread's ID */
|
||||
struct dcb *next; /**< Next DCB in owning thread's list */
|
||||
struct dcb *tail; /**< Last DCB in owning thread's list */
|
||||
} thread;
|
||||
skygw_chk_t dcb_chk_tail;
|
||||
} DCB;
|
||||
|
||||
@ -288,7 +291,7 @@ typedef struct dcb
|
||||
.cb_lock = SPINLOCK_INIT, .pollinlock = SPINLOCK_INIT, \
|
||||
.fd = DCBFD_CLOSED, .stats = DCBSTATS_INIT, .ssl_state = SSL_HANDSHAKE_UNKNOWN, \
|
||||
.state = DCB_STATE_ALLOC, .polloutlock = SPINLOCK_INIT, .dcb_chk_tail = CHK_NUM_DCB, \
|
||||
.authenticator_data = NULL, .thr_next = NULL, .thr_tail = NULL}
|
||||
.authenticator_data = NULL, .thread = {0}}
|
||||
|
||||
/**
|
||||
* The DCB usage filer used for returning DCB's in use for a certain reason
|
||||
|
@ -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]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user