From d42557401c8702ca33f90b68ad9c5ce4db7bf56e Mon Sep 17 00:00:00 2001 From: John Levon Date: Mon, 13 Sep 2021 10:27:16 +0000 Subject: [PATCH] lib/thread: improve error message for wrong thread context Signed-off-by: John Levon Change-Id: Id591f8566df1d6522742461501f750aa9a52a190 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9480 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- lib/thread/thread.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/thread/thread.c b/lib/thread/thread.c index 52f6e1762..ed12b0618 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -1550,6 +1550,16 @@ spdk_poller_register_named(spdk_poller_fn fn, return poller_register(fn, arg, period_microseconds, name); } +static void +wrong_thread(const char *func, const char *name, struct spdk_thread *thread, + struct spdk_thread *curthread) +{ + SPDK_ERRLOG("%s(%s) called from wrong thread %s:%lu (should be " + "%s:%lu)\n", func, name, curthread->name, curthread->id, + thread->name, thread->id); + assert(false); +} + void spdk_poller_unregister(struct spdk_poller **ppoller) { @@ -1570,8 +1580,7 @@ spdk_poller_unregister(struct spdk_poller **ppoller) } if (poller->thread != thread) { - SPDK_ERRLOG("different from the thread that called spdk_poller_register()\n"); - assert(false); + wrong_thread(__func__, poller->name, poller->thread, thread); return; } @@ -1606,8 +1615,7 @@ spdk_poller_pause(struct spdk_poller *poller) } if (poller->thread != thread) { - SPDK_ERRLOG("different from the thread that called spdk_poller_pause()\n"); - assert(false); + wrong_thread(__func__, poller->name, poller->thread, thread); return; } @@ -1643,8 +1651,7 @@ spdk_poller_resume(struct spdk_poller *poller) } if (poller->thread != thread) { - SPDK_ERRLOG("different from the thread that called spdk_poller_resume()\n"); - assert(false); + wrong_thread(__func__, poller->name, poller->thread, thread); return; } @@ -2199,8 +2206,7 @@ spdk_put_io_channel(struct spdk_io_channel *ch) } if (ch->thread != thread) { - SPDK_ERRLOG("different from the thread that called get_io_channel()\n"); - assert(false); + wrong_thread(__func__, "ch", ch->thread, thread); return; } @@ -2556,8 +2562,7 @@ spdk_interrupt_unregister(struct spdk_interrupt **pintr) } if (intr->thread != thread) { - SPDK_ERRLOG("different from the thread that called spdk_interrupt_register()\n"); - assert(false); + wrong_thread(__func__, intr->name, intr->thread, thread); return; } @@ -2578,8 +2583,7 @@ spdk_interrupt_set_event_types(struct spdk_interrupt *intr, } if (intr->thread != thread) { - SPDK_ERRLOG("different from the thread that called spdk_interrupt_register()\n"); - assert(false); + wrong_thread(__func__, intr->name, intr->thread, thread); return -EINVAL; }