thread: Assign not pointer but instance of spdk_cpuset in struct spdk_thread

This will reduce potential malloc failures.

Change-Id: Ie67554fec877e33bbd1044fc61eb4d79df306168
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/459717
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-06-28 13:15:16 +09:00 committed by Changpeng Liu
parent 6de3d418df
commit 752fa1ca27

View File

@ -109,7 +109,7 @@ struct spdk_thread {
bool exit;
struct spdk_cpuset *cpumask;
struct spdk_cpuset cpumask;
uint64_t tsc_last;
struct spdk_thread_stats stats;
@ -228,8 +228,6 @@ _free_thread(struct spdk_thread *thread)
TAILQ_REMOVE(&g_threads, thread, tailq);
pthread_mutex_unlock(&g_devlist_mutex);
spdk_cpuset_free(thread->cpumask);
msg = SLIST_FIRST(&thread->msg_cache);
while (msg != NULL) {
SLIST_REMOVE_HEAD(&thread->msg_cache, link);
@ -260,17 +258,10 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask)
return NULL;
}
thread->cpumask = spdk_cpuset_alloc();
if (!thread->cpumask) {
free(thread);
SPDK_ERRLOG("Unable to allocate memory for CPU mask\n");
return NULL;
}
if (cpumask) {
spdk_cpuset_copy(thread->cpumask, cpumask);
spdk_cpuset_copy(&thread->cpumask, cpumask);
} else {
spdk_cpuset_negate(thread->cpumask);
spdk_cpuset_negate(&thread->cpumask);
}
TAILQ_INIT(&thread->io_channels);
@ -284,7 +275,6 @@ spdk_thread_create(const char *name, struct spdk_cpuset *cpumask)
thread->messages = spdk_ring_create(SPDK_RING_TYPE_MP_SC, 65536, SPDK_ENV_SOCKET_ID_ANY);
if (!thread->messages) {
SPDK_ERRLOG("Unable to allocate memory for message ring\n");
spdk_cpuset_free(thread->cpumask);
free(thread);
return NULL;
}
@ -367,7 +357,7 @@ spdk_thread_get_ctx(struct spdk_thread *thread)
struct spdk_cpuset *
spdk_thread_get_cpumask(struct spdk_thread *thread)
{
return thread->cpumask;
return &thread->cpumask;
}
struct spdk_thread *