diff --git a/include/spdk/thread.h b/include/spdk/thread.h index 00590e4fd..63cb7b31b 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -151,6 +151,7 @@ struct spdk_io_channel { struct spdk_thread *thread; struct io_device *dev; uint32_t ref; + uint32_t destroy_ref; TAILQ_ENTRY(spdk_io_channel) tailq; spdk_io_channel_destroy_cb destroy_cb; diff --git a/lib/thread/thread.c b/lib/thread/thread.c index bf484ccee..7c91cac94 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -519,6 +519,7 @@ spdk_get_io_channel(void *io_device) ch->destroy_cb = dev->destroy_cb; ch->thread = thread; ch->ref = 1; + ch->destroy_ref = 0; TAILQ_INSERT_TAIL(&thread->io_channels, ch, tailq); SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Get io_channel %p for io_device %s (%p) on thread %s refcnt %u\n", @@ -553,7 +554,9 @@ _spdk_put_io_channel(void *arg) assert(ch->thread == spdk_get_thread()); - if (ch->ref > 0) { + ch->destroy_ref--; + + if (ch->ref > 0 || ch->destroy_ref > 0) { /* * Another reference to the associated io_device was requested * after this message was sent but before it had a chance to @@ -598,6 +601,7 @@ spdk_put_io_channel(struct spdk_io_channel *ch) ch->ref--; if (ch->ref == 0) { + ch->destroy_ref++; spdk_thread_send_msg(ch->thread, _spdk_put_io_channel, ch); } }