Commit 1b1967bd authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

thread: add spdk_thread_is_app_thread()



This simply returns true if the current spdk_thread
is the app thread.

This is a simpler replacement for:

spdk_thread_get_app_thread() == spdk_get_thread()

Signed-off-by: default avatarJim Harris <james.r.harris@intel.com>
Change-Id: Ib8754d4ecb91ee8bfb024e8c0b74c42bb8282b32
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18355


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent bef7abee
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ static __thread bool g_internal_thread = false;
static void
spdk_fio_sync_run_oat(void (*msg_fn)(void *), struct spdk_fio_oat_ctx *ctx)
{
	assert(spdk_get_thread() != spdk_thread_get_app_thread());
	assert(!spdk_thread_is_app_thread(NULL));

	pthread_mutex_init(&ctx->mutex, NULL);
	pthread_cond_init(&ctx->cond, NULL);
+8 −0
Original line number Diff line number Diff line
@@ -241,6 +241,14 @@ struct spdk_thread *spdk_thread_create(const char *name, const struct spdk_cpuse
 */
struct spdk_thread *spdk_thread_get_app_thread(void);

/**
 * Check if the specified spdk_thread is the app thread.
 *
 * \param thread The thread to check. If NULL, check the current spdk_thread.
 * \return true if the specified spdk_thread is the app thread, false otherwise.
 */
bool spdk_thread_is_app_thread(struct spdk_thread *thread);

/**
 * Force the current system thread to act as if executing the given SPDK thread.
 *
+2 −2
Original line number Diff line number Diff line
@@ -774,7 +774,7 @@ spdk_bdev_examine(const char *name)
	struct spdk_bdev_examine_item *item;
	struct spdk_thread *thread = spdk_get_thread();

	if (spdk_unlikely(spdk_thread_get_app_thread() != thread)) {
	if (spdk_unlikely(!spdk_thread_is_app_thread(thread))) {
		SPDK_ERRLOG("Cannot examine bdev %s on thread %p (%s)\n", name, thread,
			    thread ? spdk_thread_get_name(thread) : "null");
		return -EINVAL;
@@ -7949,7 +7949,7 @@ spdk_bdev_register(struct spdk_bdev *bdev)
	struct spdk_thread *thread = spdk_get_thread();
	int rc;

	if (spdk_unlikely(spdk_thread_get_app_thread() != spdk_get_thread())) {
	if (spdk_unlikely(!spdk_thread_is_app_thread(NULL))) {
		SPDK_ERRLOG("Cannot examine bdev %s on thread %p (%s)\n", bdev->name, thread,
			    thread ? spdk_thread_get_name(thread) : "null");
		return -EINVAL;
+2 −2
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ app_setup_signal_handlers(struct spdk_app_opts *opts)
static void
app_start_application(void)
{
	assert(spdk_get_thread() == spdk_thread_get_app_thread());
	assert(spdk_thread_is_app_thread(NULL));

	g_start_fn(g_start_arg);
}
@@ -1274,7 +1274,7 @@ rpc_framework_start_init_cpl(int rc, void *arg1)
{
	struct spdk_jsonrpc_request *request = arg1;

	assert(spdk_get_thread() == spdk_thread_get_app_thread());
	assert(spdk_thread_is_app_thread(NULL));

	if (rc) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
+2 −2
Original line number Diff line number Diff line
@@ -422,7 +422,7 @@ spdk_reactor_set_interrupt_mode(uint32_t lcore, bool new_in_interrupt,
		return -ENOTSUP;
	}

	if (spdk_get_thread() != spdk_thread_get_app_thread()) {
	if (!spdk_thread_is_app_thread(NULL)) {
		SPDK_ERRLOG("It is only permitted within spdk application thread.\n");
		return -EPERM;
	}
@@ -979,7 +979,7 @@ reactor_run(void *arg)
		 * for the app thread.
		 */
		if (spdk_thread_is_running(thread)) {
			if (thread != spdk_thread_get_app_thread()) {
			if (!spdk_thread_is_app_thread(thread)) {
				SPDK_ERRLOG("spdk_thread_exit() was not called on thread '%s'\n",
					    spdk_thread_get_name(thread));
				SPDK_ERRLOG("This will result in a non-zero exit code in a future release.\n");
Loading