io_channel: add helper to get an I/O channel's thread

This is faster than spdk_get_thread(), which iterates over all of the
threads under a lock until it finds the current one.

Change-Id: I957a68438efb5b7d632d2b9b1b567fed7714e02a
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/365079
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2017-06-12 15:56:09 -07:00 committed by Jim Harris
parent 73c9bd296a
commit c013322dc6
2 changed files with 13 additions and 0 deletions

View File

@ -78,6 +78,8 @@ void spdk_free_thread(void);
/**
* \brief Get a handle to the current thread. This handle may be passed
* to other threads and used as the target of spdk_thread_send_msg().
*
* \sa spdk_io_channel_get_thread()
*/
struct spdk_thread *spdk_get_thread(void);
@ -140,6 +142,11 @@ void spdk_put_io_channel(struct spdk_io_channel *ch);
*/
void *spdk_io_channel_get_ctx(struct spdk_io_channel *ch);
/**
* \brief Returns the spdk_thread associated with an I/O channel.
*/
struct spdk_thread *spdk_io_channel_get_thread(struct spdk_io_channel *ch);
/**
* \brief Call 'fn' on each channel associated with io_device. This happens
* asynchronously, so fn may be called after spdk_for_each_channel returns.

View File

@ -296,6 +296,12 @@ spdk_io_channel_get_ctx(struct spdk_io_channel *ch)
return (uint8_t *)ch + sizeof(*ch);
}
struct spdk_thread *
spdk_io_channel_get_thread(struct spdk_io_channel *ch)
{
return ch->thread;
}
struct call_channel {
void *io_device;
spdk_channel_msg fn;