thread: Minimize scope of internal locking
Now that the thread is stored in a thread local variable, the scope of the locking can be greatly reduced. Change-Id: Ic44934fff352be0fa5d54746226ef707aceae7b5 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/435940 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
93c7efbbe8
commit
978725c020
@ -192,12 +192,9 @@ spdk_allocate_thread(spdk_thread_pass_msg msg_fn,
|
|||||||
{
|
{
|
||||||
struct spdk_thread *thread;
|
struct spdk_thread *thread;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_devlist_mutex);
|
|
||||||
|
|
||||||
thread = _get_thread();
|
thread = _get_thread();
|
||||||
if (thread) {
|
if (thread) {
|
||||||
SPDK_ERRLOG("Double allocated SPDK thread\n");
|
SPDK_ERRLOG("Double allocated SPDK thread\n");
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +207,6 @@ spdk_allocate_thread(spdk_thread_pass_msg msg_fn,
|
|||||||
thread = calloc(1, sizeof(*thread));
|
thread = calloc(1, sizeof(*thread));
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
SPDK_ERRLOG("Unable to allocate memory for thread\n");
|
SPDK_ERRLOG("Unable to allocate memory for thread\n");
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,8 +216,6 @@ spdk_allocate_thread(spdk_thread_pass_msg msg_fn,
|
|||||||
thread->stop_poller_fn = stop_poller_fn;
|
thread->stop_poller_fn = stop_poller_fn;
|
||||||
thread->thread_ctx = thread_ctx;
|
thread->thread_ctx = thread_ctx;
|
||||||
TAILQ_INIT(&thread->io_channels);
|
TAILQ_INIT(&thread->io_channels);
|
||||||
TAILQ_INSERT_TAIL(&g_threads, thread, tailq);
|
|
||||||
|
|
||||||
TAILQ_INIT(&thread->active_pollers);
|
TAILQ_INIT(&thread->active_pollers);
|
||||||
TAILQ_INIT(&thread->timer_pollers);
|
TAILQ_INIT(&thread->timer_pollers);
|
||||||
|
|
||||||
@ -229,11 +223,9 @@ spdk_allocate_thread(spdk_thread_pass_msg msg_fn,
|
|||||||
if (!thread->messages) {
|
if (!thread->messages) {
|
||||||
SPDK_ERRLOG("Unable to allocate memory for message ring\n");
|
SPDK_ERRLOG("Unable to allocate memory for message ring\n");
|
||||||
free(thread);
|
free(thread);
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_thread_count++;
|
|
||||||
if (name) {
|
if (name) {
|
||||||
_set_thread_name(name);
|
_set_thread_name(name);
|
||||||
thread->name = strdup(name);
|
thread->name = strdup(name);
|
||||||
@ -243,6 +235,9 @@ spdk_allocate_thread(spdk_thread_pass_msg msg_fn,
|
|||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Allocating new thread %s\n", thread->name);
|
SPDK_DEBUGLOG(SPDK_LOG_THREAD, "Allocating new thread %s\n", thread->name);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&g_devlist_mutex);
|
||||||
|
TAILQ_INSERT_TAIL(&g_threads, thread, tailq);
|
||||||
|
g_thread_count++;
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
pthread_mutex_unlock(&g_devlist_mutex);
|
||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
@ -260,12 +255,9 @@ spdk_free_thread(void)
|
|||||||
struct spdk_thread *thread;
|
struct spdk_thread *thread;
|
||||||
struct spdk_io_channel *ch;
|
struct spdk_io_channel *ch;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_devlist_mutex);
|
|
||||||
|
|
||||||
thread = _get_thread();
|
thread = _get_thread();
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
SPDK_ERRLOG("No thread allocated\n");
|
SPDK_ERRLOG("No thread allocated\n");
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,9 +268,12 @@ spdk_free_thread(void)
|
|||||||
thread->name, ch->dev->name);
|
thread->name, ch->dev->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_lock(&g_devlist_mutex);
|
||||||
assert(g_thread_count > 0);
|
assert(g_thread_count > 0);
|
||||||
g_thread_count--;
|
g_thread_count--;
|
||||||
TAILQ_REMOVE(&g_threads, thread, tailq);
|
TAILQ_REMOVE(&g_threads, thread, tailq);
|
||||||
|
pthread_mutex_unlock(&g_devlist_mutex);
|
||||||
|
|
||||||
free(thread->name);
|
free(thread->name);
|
||||||
|
|
||||||
if (thread->messages) {
|
if (thread->messages) {
|
||||||
@ -288,8 +283,6 @@ spdk_free_thread(void)
|
|||||||
free(thread);
|
free(thread);
|
||||||
|
|
||||||
tls_thread = NULL;
|
tls_thread = NULL;
|
||||||
|
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t
|
static inline uint32_t
|
||||||
@ -457,15 +450,11 @@ spdk_get_thread(void)
|
|||||||
{
|
{
|
||||||
struct spdk_thread *thread;
|
struct spdk_thread *thread;
|
||||||
|
|
||||||
pthread_mutex_lock(&g_devlist_mutex);
|
|
||||||
|
|
||||||
thread = _get_thread();
|
thread = _get_thread();
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
SPDK_ERRLOG("No thread allocated\n");
|
SPDK_ERRLOG("No thread allocated\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&g_devlist_mutex);
|
|
||||||
|
|
||||||
return thread;
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user