thread: extract send_msg_notification func

Change-Id: Ib83c53b138614ba9889969c1f98e1a5bdf7fee42
Signed-off-by: Liu Xiaodong <xiaodong.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7153
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Liu Xiaodong 2021-03-31 05:27:28 -04:00 committed by Tomasz Zawadzki
parent fbd6c30b8b
commit 8c4c8c3967

View File

@ -887,6 +887,23 @@ spdk_thread_get_last_tsc(struct spdk_thread *thread)
return thread->tsc_last; return thread->tsc_last;
} }
static inline int
thread_send_msg_notification(const struct spdk_thread *target_thread)
{
uint64_t notify = 1;
int rc;
if (target_thread->interrupt_mode) {
rc = write(target_thread->msg_fd, &notify, sizeof(notify));
if (rc < 0) {
SPDK_ERRLOG("failed to notify msg_queue: %s.\n", spdk_strerror(errno));
return -EIO;
}
}
return 0;
}
int int
spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx) spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx)
{ {
@ -931,17 +948,7 @@ spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx
return -EIO; return -EIO;
} }
if (thread->interrupt_mode) { return thread_send_msg_notification(thread);
uint64_t notify = 1;
rc = write(thread->msg_fd, &notify, sizeof(notify));
if (rc < 0) {
SPDK_ERRLOG("failed to notify msg_queue: %s.\n", spdk_strerror(errno));
return -EIO;
}
}
return 0;
} }
int int
@ -949,23 +956,12 @@ spdk_thread_send_critical_msg(struct spdk_thread *thread, spdk_msg_fn fn)
{ {
spdk_msg_fn expected = NULL; spdk_msg_fn expected = NULL;
if (__atomic_compare_exchange_n(&thread->critical_msg, &expected, fn, false, __ATOMIC_SEQ_CST, if (!__atomic_compare_exchange_n(&thread->critical_msg, &expected, fn, false, __ATOMIC_SEQ_CST,
__ATOMIC_SEQ_CST)) { __ATOMIC_SEQ_CST)) {
if (thread->interrupt_mode) {
uint64_t notify = 1;
int rc;
rc = write(thread->msg_fd, &notify, sizeof(notify));
if (rc < 0) {
SPDK_ERRLOG("failed to notify msg_queue: %s.\n", spdk_strerror(errno));
return -EIO; return -EIO;
} }
}
return 0; return thread_send_msg_notification(thread);
}
return -EIO;
} }
#ifdef __linux__ #ifdef __linux__