From d2d46658d733e3ee45cde453893214f306378e4f Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 27 Sep 2022 17:24:47 -0400 Subject: [PATCH] libroot: Move threads.c to libstdthread folder and rename to match FreeBSD. It was introduced long ago, now that we have the same folder as FreeBSD does we should put it in the same place. Synchronize with FreeBSD while at it. --- src/system/libroot/posix/Jamfile | 2 +- .../posix/{threads.c => libstdthreads/thrd.c} | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) rename src/system/libroot/posix/{threads.c => libstdthreads/thrd.c} (93%) diff --git a/src/system/libroot/posix/Jamfile b/src/system/libroot/posix/Jamfile index c26c1f9c73..f66043b57a 100644 --- a/src/system/libroot/posix/Jamfile +++ b/src/system/libroot/posix/Jamfile @@ -19,7 +19,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { } - local threadsLib = call_once.c cnd.c mtx.c threads.c tss.c ; + local threadsLib = call_once.c cnd.c mtx.c thrd.c tss.c ; SEARCH_SOURCE += [ FDirName $(SUBDIR) libstdthreads ] ; if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 { # the threads library is not available on gcc2 diff --git a/src/system/libroot/posix/threads.c b/src/system/libroot/posix/libstdthreads/thrd.c similarity index 93% rename from src/system/libroot/posix/threads.c rename to src/system/libroot/posix/libstdthreads/thrd.c index 42316cc463..cd5779b061 100644 --- a/src/system/libroot/posix/threads.c +++ b/src/system/libroot/posix/libstdthreads/thrd.c @@ -2,7 +2,6 @@ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2011 Ed Schouten - * Copyright (c) 2022 Dominic Martinez * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -56,7 +55,6 @@ int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) { struct thrd_param *tp; - int error; /* * Work around return type inconsistency. Wrap execution using @@ -67,12 +65,8 @@ thrd_create(thrd_t *thr, thrd_start_t func, void *arg) return (thrd_nomem); tp->func = func; tp->arg = arg; - - error = pthread_create(thr, NULL, thrd_entry, tp); - if (error != 0) { + if (pthread_create(thr, NULL, thrd_entry, tp) != 0) { free(tp); - if (error == EAGAIN) - return (thrd_busy); return (thrd_error); } return (thrd_success); @@ -81,12 +75,14 @@ thrd_create(thrd_t *thr, thrd_start_t func, void *arg) thrd_t thrd_current(void) { + return (pthread_self()); } int thrd_detach(thrd_t thr) { + if (pthread_detach(thr) != 0) return (thrd_error); return (thrd_success); @@ -95,12 +91,14 @@ thrd_detach(thrd_t thr) int thrd_equal(thrd_t thr0, thrd_t thr1) { + return (pthread_equal(thr0, thr1)); } _Noreturn void thrd_exit(int res) { + pthread_exit((void *)(intptr_t)res); } @@ -119,11 +117,13 @@ thrd_join(thrd_t thr, int *res) int thrd_sleep(const struct timespec *duration, struct timespec *remaining) { + return (nanosleep(duration, remaining)); } void thrd_yield(void) { + sched_yield(); }