From 8c4c8c39676b152aed91b5077e351382d2a23837 Mon Sep 17 00:00:00 2001 From: Liu Xiaodong Date: Wed, 31 Mar 2021 05:27:28 -0400 Subject: [PATCH] thread: extract send_msg_notification func Change-Id: Ib83c53b138614ba9889969c1f98e1a5bdf7fee42 Signed-off-by: Liu Xiaodong Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7153 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- lib/thread/thread.c | 48 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 19f3d9904..34573a520 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -887,6 +887,23 @@ spdk_thread_get_last_tsc(struct spdk_thread *thread) 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, ¬ify, sizeof(notify)); + if (rc < 0) { + SPDK_ERRLOG("failed to notify msg_queue: %s.\n", spdk_strerror(errno)); + return -EIO; + } + } + + return 0; +} + int 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; } - if (thread->interrupt_mode) { - uint64_t notify = 1; - - rc = write(thread->msg_fd, ¬ify, sizeof(notify)); - if (rc < 0) { - SPDK_ERRLOG("failed to notify msg_queue: %s.\n", spdk_strerror(errno)); - return -EIO; - } - } - - return 0; + return thread_send_msg_notification(thread); } int @@ -949,23 +956,12 @@ spdk_thread_send_critical_msg(struct spdk_thread *thread, spdk_msg_fn fn) { spdk_msg_fn expected = NULL; - if (__atomic_compare_exchange_n(&thread->critical_msg, &expected, fn, false, __ATOMIC_SEQ_CST, - __ATOMIC_SEQ_CST)) { - if (thread->interrupt_mode) { - uint64_t notify = 1; - int rc; - - rc = write(thread->msg_fd, ¬ify, sizeof(notify)); - if (rc < 0) { - SPDK_ERRLOG("failed to notify msg_queue: %s.\n", spdk_strerror(errno)); - return -EIO; - } - } - - return 0; + if (!__atomic_compare_exchange_n(&thread->critical_msg, &expected, fn, false, __ATOMIC_SEQ_CST, + __ATOMIC_SEQ_CST)) { + return -EIO; } - return -EIO; + return thread_send_msg_notification(thread); } #ifdef __linux__