CLEANUP: refactored the notify_io_complete() function.
@@ -485,37 +485,40 @@ void notify_io_complete(const void *cookie, ENGINE_ERROR_CODE status)
return;
}
- int notify = 0;
- int pended = 0;
+ bool notify_thread = false;
+ bool premature_notify = false;
LOCK_THREAD(thr);
- if (thr != conn->thread || conn->state == conn_closing || !conn->io_blocked) {
- conn->premature_io_complete = true;
- } else {
+ if (thr == conn->thread && conn->state != conn_closing) {
+ if (conn->io_blocked) {
conn->io_blocked = false;
conn->aiostat = status;
- pended = number_of_pending(conn, thr->pending_io);
+ int pended = number_of_pending(conn, thr->pending_io);
if (pended == 0) {
if (thr->pending_io == NULL) {
- notify = 1;
+ notify_thread = true;
}
conn->next = thr->pending_io;
thr->pending_io = conn;
pended = 1;
}
assert(pended == 1);
+ } else {
+ conn->premature_io_complete = true;
+ premature_notify = true;
+ }
}
UNLOCK_THREAD(thr);
- if (notify) {
+ if (notify_thread) {
/* kick the thread in the butt */
if (write(thr->notify_send_fd, "", 1) != 1) {
mc_logger->log(EXTENSION_LOG_WARNING, NULL,
"Writing to thread notify pipe: %s", strerror(errno));
}
} else {
- if (pended == 0) {
+ if (premature_notify) {
mc_logger->log(EXTENSION_LOG_DEBUG, NULL,
"Premature notify_io_complete\n");
}
