]> git.ipfire.org Git - thirdparty/glibc.git/blame - htl/cthreads-compat.c
x86: In ld.so, diagnose missing APX support in APX-only builds
[thirdparty/glibc.git] / htl / cthreads-compat.c
CommitLineData
33574c17 1/* Compatibility routines for cthreads.
dff8da6b 2 Copyright (C) 2000-2024 Free Software Foundation, Inc.
33574c17
ST
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
ad2b41bf
ST
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
33574c17
ST
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ad2b41bf 13 Lesser General Public License for more details.
33574c17 14
ad2b41bf
ST
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
33574c17
ST
18
19#include <assert.h>
20#include <pthreadP.h>
21
22#define CTHREAD_KEY_INVALID (__cthread_key_t) -1
23
24void
25__cthread_detach (__cthread_t thread)
26{
27 int err;
62d6c330 28 pthread_t pthread = (pthread_t) (uintptr_t) thread;
33574c17 29
62d6c330 30 err = __pthread_detach (pthread);
33574c17
ST
31 assert_perror (err);
32}
33weak_alias (__cthread_detach, cthread_detach)
34
35__cthread_t
36__cthread_fork (__cthread_fn_t func, void *arg)
37{
38 pthread_t thread;
39 int err;
40
f6fb29d2 41 err = __pthread_create (&thread, NULL, func, arg);
33574c17
ST
42 assert_perror (err);
43
62d6c330 44 return (__cthread_t) (uintptr_t) thread;
33574c17
ST
45}
46weak_alias (__cthread_fork, cthread_fork)
47
48int
49__cthread_keycreate (__cthread_key_t *key)
50{
51 error_t err;
52
f6fb29d2 53 err = __pthread_key_create (key, 0);
33574c17
ST
54 if (err)
55 {
56 errno = err;
57 *key = CTHREAD_KEY_INVALID;
58 err = -1;
59 }
60
61 return err;
62}
63weak_alias (__cthread_keycreate, cthread_keycreate)
64
65int
66__cthread_getspecific (__cthread_key_t key, void **val)
67{
f6fb29d2 68 *val = __pthread_getspecific (key);
33574c17
ST
69 return 0;
70}
71weak_alias (__cthread_getspecific, cthread_getspecific)
72
73int
74__cthread_setspecific (__cthread_key_t key, void *val)
75{
76 error_t err;
77
f6fb29d2 78 err = __pthread_setspecific (key, (const void *) val);
33574c17
ST
79 if (err)
80 {
81 errno = err;
82 err = -1;
83 }
84
85 return err;
86}
87weak_alias (__cthread_setspecific, cthread_setspecific)
88
89void
90__mutex_lock_solid (void *lock)
91{
92 __pthread_mutex_lock (lock);
93}
94
95void
96__mutex_unlock_solid (void *lock)
97{
98 if (__pthread_spin_trylock (lock) != 0)
99 /* Somebody already got the lock, that one will manage waking up others */
100 return;
101 __pthread_mutex_unlock (lock);
102}