lib/thread: Introduce thread state to distinguish exiting and exited
Add enum spdk_thread_state made of RUNNING, EXITING, and EXITED, and the current state to struct spdk_thread. The state EXITING is not actually used in this patch yet. Replace the flag exit simply by the state EXITED. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I6e5dc7184d50ae6d00e6ba00f5e2cf6045e5d48d Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1630 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
719343c94a
commit
6397735bc9
@ -77,12 +77,25 @@ struct spdk_poller {
|
|||||||
char name[SPDK_MAX_POLLER_NAME_LEN + 1];
|
char name[SPDK_MAX_POLLER_NAME_LEN + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum spdk_thread_state {
|
||||||
|
/* The thread is pocessing poller and message by spdk_thread_poll(). */
|
||||||
|
SPDK_THREAD_STATE_RUNNING,
|
||||||
|
|
||||||
|
/* The thread is in the process of termination. It reaps unregistering
|
||||||
|
* poller are releasing I/O channel.
|
||||||
|
*/
|
||||||
|
SPDK_THREAD_STATE_EXITING,
|
||||||
|
|
||||||
|
/* The thread is exited. It is ready to call spdk_thread_destroy(). */
|
||||||
|
SPDK_THREAD_STATE_EXITED,
|
||||||
|
};
|
||||||
|
|
||||||
struct spdk_thread {
|
struct spdk_thread {
|
||||||
TAILQ_HEAD(, spdk_io_channel) io_channels;
|
TAILQ_HEAD(, spdk_io_channel) io_channels;
|
||||||
TAILQ_ENTRY(spdk_thread) tailq;
|
TAILQ_ENTRY(spdk_thread) tailq;
|
||||||
char name[SPDK_MAX_THREAD_NAME_LEN + 1];
|
char name[SPDK_MAX_THREAD_NAME_LEN + 1];
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
bool exit;
|
enum spdk_thread_state state;
|
||||||
struct spdk_cpuset cpumask;
|
struct spdk_cpuset cpumask;
|
||||||
uint64_t tsc_last;
|
uint64_t tsc_last;
|
||||||
struct spdk_thread_stats stats;
|
struct spdk_thread_stats stats;
|
||||||
|
@ -305,6 +305,8 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thread->state = SPDK_THREAD_STATE_RUNNING;
|
||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +352,7 @@ _spdk_thread_exit(struct spdk_thread *thread)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread->exit = true;
|
thread->state = SPDK_THREAD_STATE_EXITED;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,9 +363,9 @@ spdk_thread_exit(struct spdk_thread *thread)
|
|||||||
|
|
||||||
assert(tls_thread == thread);
|
assert(tls_thread == thread);
|
||||||
|
|
||||||
if (thread->exit) {
|
if (thread->state >= SPDK_THREAD_STATE_EXITING) {
|
||||||
SPDK_INFOLOG(SPDK_LOG_THREAD,
|
SPDK_INFOLOG(SPDK_LOG_THREAD,
|
||||||
"thread %s is already marked as exited\n",
|
"thread %s is already exiting\n",
|
||||||
thread->name);
|
thread->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -374,7 +376,7 @@ spdk_thread_exit(struct spdk_thread *thread)
|
|||||||
bool
|
bool
|
||||||
spdk_thread_is_exited(struct spdk_thread *thread)
|
spdk_thread_is_exited(struct spdk_thread *thread)
|
||||||
{
|
{
|
||||||
return thread->exit;
|
return thread->state == SPDK_THREAD_STATE_EXITED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -382,7 +384,7 @@ spdk_thread_destroy(struct spdk_thread *thread)
|
|||||||
{
|
{
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Destroy thread %s\n", thread->name);
|
SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Destroy thread %s\n", thread->name);
|
||||||
|
|
||||||
assert(thread->exit == true);
|
assert(thread->state == SPDK_THREAD_STATE_EXITED);
|
||||||
|
|
||||||
if (tls_thread == thread) {
|
if (tls_thread == thread) {
|
||||||
tls_thread = NULL;
|
tls_thread = NULL;
|
||||||
@ -801,7 +803,7 @@ spdk_thread_send_msg(const struct spdk_thread *thread, spdk_msg_fn fn, void *ctx
|
|||||||
|
|
||||||
assert(thread != NULL);
|
assert(thread != NULL);
|
||||||
|
|
||||||
if (spdk_unlikely(thread->exit)) {
|
if (spdk_unlikely(thread->state == SPDK_THREAD_STATE_EXITED)) {
|
||||||
SPDK_ERRLOG("Thread %s is marked as exited.\n", thread->name);
|
SPDK_ERRLOG("Thread %s is marked as exited.\n", thread->name);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
@ -868,7 +870,7 @@ _spdk_poller_register(spdk_poller_fn fn,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_unlikely(thread->exit)) {
|
if (spdk_unlikely(thread->state == SPDK_THREAD_STATE_EXITED)) {
|
||||||
SPDK_ERRLOG("thread %s is marked as exited\n", thread->name);
|
SPDK_ERRLOG("thread %s is marked as exited\n", thread->name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1290,7 +1292,7 @@ spdk_get_io_channel(void *io_device)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_unlikely(thread->exit)) {
|
if (spdk_unlikely(thread->state == SPDK_THREAD_STATE_EXITED)) {
|
||||||
SPDK_ERRLOG("Thread %s is marked as exited\n", thread->name);
|
SPDK_ERRLOG("Thread %s is marked as exited\n", thread->name);
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
pthread_mutex_unlock(&g_devlist_mutex);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user