poll_[add|remove]_fd_[from|to]_worker made boolean

This commit is contained in:
Johan Wikman
2017-04-06 10:20:18 +03:00
parent 9829d6e365
commit 21ac606ee1
4 changed files with 35 additions and 36 deletions

View File

@ -83,9 +83,9 @@ typedef struct mxs_poll_data
*
* @attention The provided file descriptor *must* be non-blocking.
*
* @return 0 on success, non-zero on failure.
* @return True on success, false on failure.
*/
int poll_add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data);
bool poll_add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data);
/**
@ -95,8 +95,8 @@ int poll_add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data)
* the poll set of all workers; otherwise the id of a worker.
* @param fd The file descriptor to be removed.
*
* @return 0 on success, non-zero on failure.
* @return True on success, false on failure.
*/
int poll_remove_fd_from_worker(int wid, int fd);
bool poll_remove_fd_from_worker(int wid, int fd);
MXS_END_DECLS

View File

@ -3607,9 +3607,7 @@ int poll_add_dcb(DCB *dcb)
worker_id = MXS_WORKER_ANY;
}
rc = poll_add_fd_to_worker(worker_id, dcb->fd, events, (MXS_POLL_DATA*)dcb);
if (0 == rc)
if (poll_add_fd_to_worker(worker_id, dcb->fd, events, (MXS_POLL_DATA*)dcb))
{
dcb_add_to_list(dcb);
@ -3617,10 +3615,12 @@ int poll_add_dcb(DCB *dcb)
pthread_self(),
dcb,
STRDCBSTATE(dcb->state));
rc = 0;
}
else
{
dcb->state = old_state;
rc = -1;
}
return rc;
}
@ -3673,7 +3673,14 @@ int poll_remove_dcb(DCB *dcb)
worker_id = dcb->poll.thread.id;
}
rc = poll_remove_fd_from_worker(worker_id, dcbfd);
if (poll_remove_fd_from_worker(worker_id, dcbfd))
{
rc = 0;
}
else
{
rc = -1;
}
}
return rc;
}

View File

@ -289,7 +289,7 @@ poll_init()
max_poll_sleep = config_pollsleep();
}
static int add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data)
static bool add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data)
{
ss_dassert((wid >= 0) && (wid <= n_threads));
@ -308,10 +308,10 @@ static int add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* dat
rc = poll_resolve_error(fd, errno, EPOLL_CTL_ADD);
}
return rc;
return rc == 0;
}
static int add_fd_to_workers(int fd, uint32_t events, MXS_POLL_DATA* data)
static bool add_fd_to_workers(int fd, uint32_t events, MXS_POLL_DATA* data)
{
events |= EPOLLET;
@ -345,42 +345,34 @@ static int add_fd_to_workers(int fd, uint32_t events, MXS_POLL_DATA* data)
rc = poll_resolve_error(fd, stored_errno, EPOLL_CTL_ADD);
}
return rc;
return rc == 0;
}
int poll_add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data)
bool poll_add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data)
{
int rc;
bool rv;
if (wid == MXS_WORKER_ANY)
{
wid = (int)atomic_add(&next_epoll_fd, 1) % n_threads;
rc = add_fd_to_worker(wid, fd, events, data);
rv = add_fd_to_worker(wid, fd, events, data);
}
else if (wid == MXS_WORKER_ALL)
{
rc = add_fd_to_workers(fd, events, data);
rv = add_fd_to_workers(fd, events, data);
}
else
{
ss_dassert((wid >= 0) && (wid < n_threads));
if ((wid >= 0) && (wid < n_threads))
{
rc = add_fd_to_worker(wid, fd, events, data);
}
else
{
errno = EINVAL;
rc = -1;
}
rv = add_fd_to_worker(wid, fd, events, data);
}
return rc;
return rv;
}
static int remove_fd_from_worker(int wid, int fd)
static bool remove_fd_from_worker(int wid, int fd)
{
ss_dassert((wid >= 0) && (wid < n_threads));
@ -393,10 +385,10 @@ static int remove_fd_from_worker(int wid, int fd)
rc = poll_resolve_error(fd, errno, EPOLL_CTL_DEL);
}
return rc;
return rc == 0;
}
static int remove_fd_from_workers(int fd)
static bool remove_fd_from_workers(int fd)
{
int rc;
@ -407,23 +399,23 @@ static int remove_fd_from_workers(int fd)
remove_fd_from_worker(i, fd);
}
return 0;
return true;
}
int poll_remove_fd_from_worker(int wid, int fd)
bool poll_remove_fd_from_worker(int wid, int fd)
{
int rc;
bool rv;
if (wid == MXS_WORKER_ALL)
{
rc = remove_fd_from_workers(fd);
rv = remove_fd_from_workers(fd);
}
else
{
rc = remove_fd_from_worker(wid, fd);
rv = remove_fd_from_worker(wid, fd);
}
return rc;
return rv;
}
/**

View File

@ -400,7 +400,7 @@ Worker* Worker::create(int worker_id)
if (pWorker)
{
if (poll_add_fd_to_worker(worker_id, read_fd, EPOLLIN, &pWorker->m_poll) != 0)
if (!poll_add_fd_to_worker(worker_id, read_fd, EPOLLIN, &pWorker->m_poll))
{
MXS_ERROR("Could not add read descriptor of worker to poll set: %s", mxs_strerror(errno));
delete pWorker;