util/c11: Update function u_thread_create to be c11 conformance
Do not assume thrd_t to be a pointer or integer, as the C11 standard tells us: thrd_t: implementation-defined complete object type identifying a thread At https://en.cppreference.com/w/c/thread So we always return the thread creation return code instead of thrd_t value, and judge the return code properly. Signed-off-by: Yonggang Luo <luoyonggang@gmail.com> Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15087>
This commit is contained in:
parent
6e33ef2bb9
commit
a9e2c699aa
|
@ -959,8 +959,7 @@ dd_context_create(struct dd_screen *dscreen, struct pipe_context *pipe)
|
|||
list_inithead(&dctx->records);
|
||||
(void) mtx_init(&dctx->mutex, mtx_plain);
|
||||
(void) cnd_init(&dctx->cond);
|
||||
dctx->thread = u_thread_create(dd_thread_main, dctx);
|
||||
if (!dctx->thread) {
|
||||
if (thrd_success != u_thread_create(&dctx->thread,dd_thread_main, dctx)) {
|
||||
mtx_destroy(&dctx->mutex);
|
||||
goto fail;
|
||||
}
|
||||
|
|
|
@ -841,7 +841,10 @@ rbug_start(struct rbug_screen *rb_screen)
|
|||
|
||||
tr_rbug->rb_screen = rb_screen;
|
||||
tr_rbug->running = true;
|
||||
tr_rbug->thread = u_thread_create(rbug_thread, tr_rbug);
|
||||
if (thrd_success != u_thread_create(&tr_rbug->thread, rbug_thread, tr_rbug)) {
|
||||
FREE(tr_rbug);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return tr_rbug;
|
||||
}
|
||||
|
|
|
@ -96,9 +96,13 @@ lp_cs_tpool_create(unsigned num_threads)
|
|||
|
||||
list_inithead(&pool->workqueue);
|
||||
assert (num_threads <= LP_MAX_THREADS);
|
||||
for (unsigned i = 0; i < num_threads; i++) {
|
||||
if (thrd_success != u_thread_create(pool->threads + i, lp_cs_tpool_worker, pool)) {
|
||||
num_threads = i; /* previous thread is max */
|
||||
break;
|
||||
}
|
||||
}
|
||||
pool->num_threads = num_threads;
|
||||
for (unsigned i = 0; i < num_threads; i++)
|
||||
pool->threads[i] = u_thread_create(lp_cs_tpool_worker, pool);
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
|
|
@ -1238,9 +1238,8 @@ create_rast_threads(struct lp_rasterizer *rast)
|
|||
for (unsigned i = 0; i < rast->num_threads; i++) {
|
||||
pipe_semaphore_init(&rast->tasks[i].work_ready, 0);
|
||||
pipe_semaphore_init(&rast->tasks[i].work_done, 0);
|
||||
rast->threads[i] = u_thread_create(thread_function,
|
||||
(void *) &rast->tasks[i]);
|
||||
if (!rast->threads[i]) {
|
||||
if (thrd_success != u_thread_create(rast->threads + i, thread_function,
|
||||
(void *) &rast->tasks[i])) {
|
||||
rast->num_threads = i; /* previous thread is max */
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -144,24 +144,27 @@ r600_gpu_load_thread(void *param)
|
|||
|
||||
void r600_gpu_load_kill_thread(struct r600_common_screen *rscreen)
|
||||
{
|
||||
if (!rscreen->gpu_load_thread)
|
||||
if (!rscreen->gpu_load_thread_created)
|
||||
return;
|
||||
|
||||
p_atomic_inc(&rscreen->gpu_load_stop_thread);
|
||||
thrd_join(rscreen->gpu_load_thread, NULL);
|
||||
rscreen->gpu_load_thread = 0;
|
||||
rscreen->gpu_load_thread_created = false;
|
||||
}
|
||||
|
||||
static uint64_t r600_read_mmio_counter(struct r600_common_screen *rscreen,
|
||||
unsigned busy_index)
|
||||
{
|
||||
/* Start the thread if needed. */
|
||||
if (!rscreen->gpu_load_thread) {
|
||||
if (!rscreen->gpu_load_thread_created) {
|
||||
mtx_lock(&rscreen->gpu_load_mutex);
|
||||
/* Check again inside the mutex. */
|
||||
if (!rscreen->gpu_load_thread)
|
||||
rscreen->gpu_load_thread =
|
||||
u_thread_create(r600_gpu_load_thread, rscreen);
|
||||
if (!rscreen->gpu_load_thread_created) {
|
||||
int ret = u_thread_create(&rscreen->gpu_load_thread, r600_gpu_load_thread, rscreen);
|
||||
if (ret == thrd_success) {
|
||||
rscreen->gpu_load_thread_created = true;
|
||||
}
|
||||
}
|
||||
mtx_unlock(&rscreen->gpu_load_mutex);
|
||||
}
|
||||
|
||||
|
|
|
@ -360,6 +360,7 @@ struct r600_common_screen {
|
|||
/* GPU load thread. */
|
||||
mtx_t gpu_load_mutex;
|
||||
thrd_t gpu_load_thread;
|
||||
bool gpu_load_thread_created;
|
||||
union r600_mmio_counters mmio_counters;
|
||||
volatile unsigned gpu_load_stop_thread; /* bool */
|
||||
|
||||
|
|
|
@ -159,22 +159,25 @@ static int si_gpu_load_thread(void *param)
|
|||
|
||||
void si_gpu_load_kill_thread(struct si_screen *sscreen)
|
||||
{
|
||||
if (!sscreen->gpu_load_thread)
|
||||
if (!sscreen->gpu_load_thread_created)
|
||||
return;
|
||||
|
||||
p_atomic_inc(&sscreen->gpu_load_stop_thread);
|
||||
thrd_join(sscreen->gpu_load_thread, NULL);
|
||||
sscreen->gpu_load_thread = 0;
|
||||
sscreen->gpu_load_thread_created = false;
|
||||
}
|
||||
|
||||
static uint64_t si_read_mmio_counter(struct si_screen *sscreen, unsigned busy_index)
|
||||
{
|
||||
/* Start the thread if needed. */
|
||||
if (!sscreen->gpu_load_thread) {
|
||||
if (!sscreen->gpu_load_thread_created) {
|
||||
simple_mtx_lock(&sscreen->gpu_load_mutex);
|
||||
/* Check again inside the mutex. */
|
||||
if (!sscreen->gpu_load_thread)
|
||||
sscreen->gpu_load_thread = u_thread_create(si_gpu_load_thread, sscreen);
|
||||
if (!sscreen->gpu_load_thread_created) {
|
||||
if (thrd_success == u_thread_create(&sscreen->gpu_load_thread, si_gpu_load_thread, sscreen)) {
|
||||
sscreen->gpu_load_thread_created = true;
|
||||
}
|
||||
}
|
||||
simple_mtx_unlock(&sscreen->gpu_load_mutex);
|
||||
}
|
||||
|
||||
|
|
|
@ -630,6 +630,7 @@ struct si_screen {
|
|||
/* GPU load thread. */
|
||||
simple_mtx_t gpu_load_mutex;
|
||||
thrd_t gpu_load_thread;
|
||||
bool gpu_load_thread_created;
|
||||
union si_mmio_counters mmio_counters;
|
||||
volatile unsigned gpu_load_stop_thread; /* bool */
|
||||
|
||||
|
|
|
@ -163,8 +163,7 @@ nine_csmt_create( struct NineDevice9 *This )
|
|||
|
||||
ctx->device = This;
|
||||
|
||||
ctx->worker = u_thread_create(nine_csmt_worker, ctx);
|
||||
if (!ctx->worker) {
|
||||
if (thrd_success != u_thread_create(&ctx->worker, nine_csmt_worker, ctx)) {
|
||||
nine_queue_delete(ctx->pool);
|
||||
FREE(ctx);
|
||||
return NULL;
|
||||
|
|
|
@ -114,7 +114,7 @@ int main(int argc, char *argv[])
|
|||
|
||||
for (i = 0; i < NUM_THREADS; i++) {
|
||||
thread_ids[i] = i;
|
||||
threads[i] = u_thread_create(thread_function, (void *) &thread_ids[i]);
|
||||
u_thread_create(threads + i, thread_function, (void *) &thread_ids[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < NUM_THREADS; i++ ) {
|
||||
|
|
|
@ -337,9 +337,7 @@ util_queue_create_thread(struct util_queue *queue, unsigned index)
|
|||
input->queue = queue;
|
||||
input->thread_index = index;
|
||||
|
||||
queue->threads[index] = u_thread_create(util_queue_thread_func, input);
|
||||
|
||||
if (!queue->threads[index]) {
|
||||
if (thrd_success != u_thread_create(queue->threads + index, util_queue_thread_func, input)) {
|
||||
free(input);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -101,26 +101,22 @@ util_get_current_cpu(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static inline thrd_t u_thread_create(int (*routine)(void *), void *param)
|
||||
static inline int u_thread_create(thrd_t *thrd, int (*routine)(void *), void *param)
|
||||
{
|
||||
thrd_t thread;
|
||||
int ret = thrd_error;
|
||||
#ifdef HAVE_PTHREAD
|
||||
sigset_t saved_set, new_set;
|
||||
int ret;
|
||||
|
||||
sigfillset(&new_set);
|
||||
sigdelset(&new_set, SIGSYS);
|
||||
pthread_sigmask(SIG_BLOCK, &new_set, &saved_set);
|
||||
ret = thrd_create( &thread, routine, param );
|
||||
ret = thrd_create(thrd, routine, param);
|
||||
pthread_sigmask(SIG_SETMASK, &saved_set, NULL);
|
||||
#else
|
||||
int ret;
|
||||
ret = thrd_create( &thread, routine, param );
|
||||
ret = thrd_create(thrd, routine, param);
|
||||
#endif
|
||||
if (ret)
|
||||
return 0;
|
||||
|
||||
return thread;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline void u_thread_setname( const char *name )
|
||||
|
|
Loading…
Reference in New Issue