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.
This commit is contained in:
Augustin Cavalier
2022-09-27 17:24:57 -04:00
parent a3c9f71efd
commit d2d46658d7
2 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -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 ] ; SEARCH_SOURCE += [ FDirName $(SUBDIR) libstdthreads ] ;
if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 { if $(HAIKU_CC_IS_LEGACY_GCC_$(architecture)) = 1 {
# the threads library is not available on gcc2 # the threads library is not available on gcc2
@@ -2,7 +2,6 @@
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
* *
* Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org> * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
* Copyright (c) 2022 Dominic Martinez <dom@dominicm.dev>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * 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) thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
{ {
struct thrd_param *tp; struct thrd_param *tp;
int error;
/* /*
* Work around return type inconsistency. Wrap execution using * 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); return (thrd_nomem);
tp->func = func; tp->func = func;
tp->arg = arg; tp->arg = arg;
if (pthread_create(thr, NULL, thrd_entry, tp) != 0) {
error = pthread_create(thr, NULL, thrd_entry, tp);
if (error != 0) {
free(tp); free(tp);
if (error == EAGAIN)
return (thrd_busy);
return (thrd_error); return (thrd_error);
} }
return (thrd_success); return (thrd_success);
@@ -81,12 +75,14 @@ thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
thrd_t thrd_t
thrd_current(void) thrd_current(void)
{ {
return (pthread_self()); return (pthread_self());
} }
int int
thrd_detach(thrd_t thr) thrd_detach(thrd_t thr)
{ {
if (pthread_detach(thr) != 0) if (pthread_detach(thr) != 0)
return (thrd_error); return (thrd_error);
return (thrd_success); return (thrd_success);
@@ -95,12 +91,14 @@ thrd_detach(thrd_t thr)
int int
thrd_equal(thrd_t thr0, thrd_t thr1) thrd_equal(thrd_t thr0, thrd_t thr1)
{ {
return (pthread_equal(thr0, thr1)); return (pthread_equal(thr0, thr1));
} }
_Noreturn void _Noreturn void
thrd_exit(int res) thrd_exit(int res)
{ {
pthread_exit((void *)(intptr_t)res); pthread_exit((void *)(intptr_t)res);
} }
@@ -119,11 +117,13 @@ thrd_join(thrd_t thr, int *res)
int int
thrd_sleep(const struct timespec *duration, struct timespec *remaining) thrd_sleep(const struct timespec *duration, struct timespec *remaining)
{ {
return (nanosleep(duration, remaining)); return (nanosleep(duration, remaining));
} }
void void
thrd_yield(void) thrd_yield(void)
{ {
sched_yield(); sched_yield();
} }