From: Olivier Matz Date: Wed, 2 May 2018 08:49:02 +0000 (+0200) Subject: use a lock instead of a barrier X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=refs%2Fheads%2Fpthread-fix;p=dpdk.git use a lock instead of a barrier --- diff --git a/lib/librte_eal/common/eal_common_thread.c b/lib/librte_eal/common/eal_common_thread.c index de69452eb8..d8da9332af 100644 --- a/lib/librte_eal/common/eal_common_thread.c +++ b/lib/librte_eal/common/eal_common_thread.c @@ -144,7 +144,7 @@ exit: struct rte_thread_ctrl_params { void *(*start_routine)(void *); void *arg; - pthread_barrier_t configured; + pthread_mutex_t lock; }; static void *rte_thread_init(void *arg) @@ -153,7 +153,12 @@ static void *rte_thread_init(void *arg) void *(*start_routine)(void *) = params->start_routine; void *routine_arg = params->arg; - pthread_barrier_wait(¶ms->configured); + /* wait that configuration done by caller is finished */ + pthread_mutex_lock(¶ms->lock); + pthread_mutex_unlock(¶ms->lock); + + pthread_mutex_destroy(¶ms->lock); + free(params); return start_routine(routine_arg); } @@ -174,12 +179,14 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, params->start_routine = start_routine; params->arg = arg; - - pthread_barrier_init(¶ms->configured, NULL, 2); + pthread_mutex_init(¶ms->lock, NULL); + pthread_mutex_lock(¶ms->lock); ret = pthread_create(thread, attr, rte_thread_init, (void *)params); - if (ret != 0) + if (ret != 0) { + free(params); return ret; + } if (name != NULL) { ret = rte_thread_setname(*thread, name); @@ -204,8 +211,9 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, if (ret < 0) goto fail; - pthread_barrier_wait(¶ms->configured); - free(params); + pthread_mutex_unlock(¶ms->lock); + + /* params is freed by the new thread */ return 0;