]> git.ipfire.org Git - thirdparty/glibc.git/blame - htl/cthreads-compat.c
nptl/tst-cancel25 needs to be an internal test
[thirdparty/glibc.git] / htl / cthreads-compat.c
CommitLineData
33574c17 1/* Compatibility routines for cthreads.
04277e02 2 Copyright (C) 2000-2019 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;
28
f6fb29d2 29 err = __pthread_detach ((pthread_t) thread);
33574c17
ST
30 assert_perror (err);
31}
32weak_alias (__cthread_detach, cthread_detach)
33
34__cthread_t
35__cthread_fork (__cthread_fn_t func, void *arg)
36{
37 pthread_t thread;
38 int err;
39
f6fb29d2 40 err = __pthread_create (&thread, NULL, func, arg);
33574c17
ST
41 assert_perror (err);
42
43 return (__cthread_t) thread;
44}
45weak_alias (__cthread_fork, cthread_fork)
46
47int
48__cthread_keycreate (__cthread_key_t *key)
49{
50 error_t err;
51
f6fb29d2 52 err = __pthread_key_create (key, 0);
33574c17
ST
53 if (err)
54 {
55 errno = err;
56 *key = CTHREAD_KEY_INVALID;
57 err = -1;
58 }
59
60 return err;
61}
62weak_alias (__cthread_keycreate, cthread_keycreate)
63
64int
65__cthread_getspecific (__cthread_key_t key, void **val)
66{
f6fb29d2 67 *val = __pthread_getspecific (key);
33574c17
ST
68 return 0;
69}
70weak_alias (__cthread_getspecific, cthread_getspecific)
71
72int
73__cthread_setspecific (__cthread_key_t key, void *val)
74{
75 error_t err;
76
f6fb29d2 77 err = __pthread_setspecific (key, (const void *) val);
33574c17
ST
78 if (err)
79 {
80 errno = err;
81 err = -1;
82 }
83
84 return err;
85}
86weak_alias (__cthread_setspecific, cthread_setspecific)
87
88void
89__mutex_lock_solid (void *lock)
90{
91 __pthread_mutex_lock (lock);
92}
93
94void
95__mutex_unlock_solid (void *lock)
96{
97 if (__pthread_spin_trylock (lock) != 0)
98 /* Somebody already got the lock, that one will manage waking up others */
99 return;
100 __pthread_mutex_unlock (lock);
101}