diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-01-13 19:58:28 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2020-02-09 13:56:48 +0100 |
commit | b05de1040009d0d07a5a2e2765cffe554ffbe6ac (patch) | |
tree | 2b112a97ce7947699fac8b6df47e6db0b5196ded /nptl | |
parent | 6cefe985b869e7b33b05ce7252410474d8a6c3ad (diff) | |
download | glibc-b05de1040009d0d07a5a2e2765cffe554ffbe6ac.tar.gz glibc-b05de1040009d0d07a5a2e2765cffe554ffbe6ac.tar.xz glibc-b05de1040009d0d07a5a2e2765cffe554ffbe6ac.zip |
C11 threads: Move implementation to sysdeps/pthread
so it gets shared by nptl and htl. Also add htl versions of thrd_current and thrd_yield. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'nptl')
36 files changed, 3 insertions, 1538 deletions
diff --git a/nptl/Makefile b/nptl/Makefile index ae530a5bae..f762ea26a3 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -22,7 +22,7 @@ subdir := nptl include ../Makeconfig -headers := pthread.h semaphore.h bits/semaphore.h threads.h \ +headers := pthread.h semaphore.h bits/semaphore.h \ bits/struct_mutex.h bits/struct_rwlock.h extra-libs := libpthread @@ -30,8 +30,7 @@ extra-libs-others := $(extra-libs) routines = alloca_cutoff forward libc-lowlevellock libc-cancellation \ libc-cleanup libc_pthread_init libc_multiple_threads \ - register-atfork pthread_atfork pthread_self thrd_current \ - thrd_equal thrd_sleep thrd_yield pthread_equal \ + register-atfork pthread_atfork pthread_self pthread_equal \ pthread_attr_destroy pthread_attr_init pthread_attr_getdetachstate \ pthread_attr_setdetachstate pthread_attr_getinheritsched \ pthread_attr_setinheritsched pthread_attr_getschedparam \ @@ -141,11 +140,7 @@ libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \ pthread_mutex_setprioceiling \ pthread_setname pthread_getname \ pthread_setattr_default_np pthread_getattr_default_np \ - thrd_create thrd_detach thrd_exit thrd_join \ - mtx_destroy mtx_init mtx_lock mtx_timedlock \ - mtx_trylock mtx_unlock call_once cnd_broadcast \ - cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait \ - tss_create tss_delete tss_get tss_set pthread_mutex_conf \ + pthread_mutex_conf \ libpthread-compat # pthread_setuid pthread_seteuid pthread_setreuid \ # pthread_setresuid \ @@ -319,9 +314,6 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \ tst-robust-fork tst-create-detached tst-memstream \ tst-thread-exit-clobber tst-minstack-cancel tst-minstack-exit \ tst-minstack-throw \ - tst-cnd-basic tst-mtx-trylock tst-cnd-broadcast \ - tst-cnd-timedwait tst-thrd-detach tst-mtx-basic tst-thrd-sleep \ - tst-mtx-recursive tst-tss-basic tst-call-once tst-mtx-timedlock \ tst-rwlock-pwn \ tst-rwlock-tryrdlock-stall tst-rwlock-trywrlock-stall \ tst-unwind-thread diff --git a/nptl/call_once.c b/nptl/call_once.c deleted file mode 100644 index 25e2964c76..0000000000 --- a/nptl/call_once.c +++ /dev/null @@ -1,31 +0,0 @@ -/* C11 threads call once implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <stdalign.h> - -#include "thrd_priv.h" - -void -call_once (once_flag *flag, void (*func)(void)) -{ - _Static_assert (sizeof (once_flag) == sizeof (pthread_once_t), - "sizeof (once_flag) != sizeof (pthread_once_t)"); - _Static_assert (alignof (once_flag) == alignof (pthread_once_t), - "alignof (once_flag) != alignof (pthread_once_t)"); - __pthread_once ((pthread_once_t *) flag, func); -} diff --git a/nptl/cnd_broadcast.c b/nptl/cnd_broadcast.c deleted file mode 100644 index 66e0fce0c6..0000000000 --- a/nptl/cnd_broadcast.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 thread conditional broadcast implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -cnd_broadcast (cnd_t *cond) -{ - int err_code = __pthread_cond_broadcast ((pthread_cond_t*) cond); - return thrd_err_map (err_code); -} diff --git a/nptl/cnd_destroy.c b/nptl/cnd_destroy.c deleted file mode 100644 index 763e91cb0f..0000000000 --- a/nptl/cnd_destroy.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 threads conditional destroy implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" -#include "pthreadP.h" - -void -cnd_destroy (cnd_t *cond) -{ - __pthread_cond_destroy ((pthread_cond_t *) cond); -} diff --git a/nptl/cnd_init.c b/nptl/cnd_init.c deleted file mode 100644 index e8d7d68a2c..0000000000 --- a/nptl/cnd_init.c +++ /dev/null @@ -1,33 +0,0 @@ -/* C11 thread conditional initialization implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <stdalign.h> - -#include "thrd_priv.h" - -int -cnd_init (cnd_t *cond) -{ - _Static_assert (sizeof (cnd_t) == sizeof (pthread_cond_t), - "(sizeof (cnd_t) != sizeof (pthread_cond_t)"); - _Static_assert (alignof (cnd_t) == alignof (pthread_cond_t), - "alignof (cnd_t) != alignof (pthread_cond_t)"); - - int err_code = __pthread_cond_init ((pthread_cond_t *)cond, NULL); - return thrd_err_map (err_code); -} diff --git a/nptl/cnd_signal.c b/nptl/cnd_signal.c deleted file mode 100644 index 27155ffc1b..0000000000 --- a/nptl/cnd_signal.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 threads conditional signal implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -cnd_signal (cnd_t *cond) -{ - int err_code = __pthread_cond_signal ((pthread_cond_t *) cond); - return thrd_err_map (err_code); -} diff --git a/nptl/cnd_timedwait.c b/nptl/cnd_timedwait.c deleted file mode 100644 index c7f5309cf7..0000000000 --- a/nptl/cnd_timedwait.c +++ /dev/null @@ -1,29 +0,0 @@ -/* C11 threads conditional timed wait implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -cnd_timedwait (cnd_t *restrict cond, mtx_t *restrict mutex, - const struct timespec* restrict time_point) -{ - int err_code = __pthread_cond_timedwait ((pthread_cond_t *) cond, - (pthread_mutex_t *) mutex, - time_point); - return thrd_err_map (err_code); -} diff --git a/nptl/cnd_wait.c b/nptl/cnd_wait.c deleted file mode 100644 index 8070ca7c6a..0000000000 --- a/nptl/cnd_wait.c +++ /dev/null @@ -1,27 +0,0 @@ -/* C11 threads conditional wait implementaiton. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -cnd_wait (cnd_t *cond, mtx_t *mutex) -{ - int err_code = __pthread_cond_wait ((pthread_cond_t *) cond, - (pthread_mutex_t *) mutex); - return thrd_err_map (err_code); -} diff --git a/nptl/mtx_destroy.c b/nptl/mtx_destroy.c deleted file mode 100644 index 9ac324c8f8..0000000000 --- a/nptl/mtx_destroy.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 threads mutex destroy implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" -#include "pthreadP.h" - -void -mtx_destroy (mtx_t *mutex) -{ - __pthread_mutex_destroy ((pthread_mutex_t *) mutex); -} diff --git a/nptl/mtx_init.c b/nptl/mtx_init.c deleted file mode 100644 index 436a03673e..0000000000 --- a/nptl/mtx_init.c +++ /dev/null @@ -1,53 +0,0 @@ -/* C11 threads mutex initialization implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <stdalign.h> - -#include "thrd_priv.h" - -int -mtx_init (mtx_t *mutex, int type) -{ - _Static_assert (sizeof (mtx_t) == sizeof (pthread_mutex_t), - "sizeof (mtx_t) != sizeof (pthread_mutex_t)"); - _Static_assert (alignof (mtx_t) == alignof (pthread_mutex_t), - "alignof (mtx_t) != alignof (pthread_mutex_t)"); - - pthread_mutexattr_t attr; - - __pthread_mutexattr_init (&attr); - - /* Another possible solution would be to set the flags directly in - mutex object. */ - switch (type) - { - case mtx_plain | mtx_recursive: - case mtx_timed | mtx_recursive: - __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE); - break; - case mtx_plain: - case mtx_timed: /* No difference between both in standard */ - default: - __pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_NORMAL); - break; - } - - int err_code = __pthread_mutex_init ((pthread_mutex_t *) mutex, &attr); - /* pthread_mutexattr_destroy implementation is a noop. */ - return thrd_err_map (err_code); -} diff --git a/nptl/mtx_lock.c b/nptl/mtx_lock.c deleted file mode 100644 index cf1632b3f2..0000000000 --- a/nptl/mtx_lock.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 threads mutex lock implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -mtx_lock (mtx_t *mutex) -{ - int err_code = __pthread_mutex_lock ((pthread_mutex_t *) mutex); - return thrd_err_map (err_code); -} diff --git a/nptl/mtx_timedlock.c b/nptl/mtx_timedlock.c deleted file mode 100644 index d55cf99d11..0000000000 --- a/nptl/mtx_timedlock.c +++ /dev/null @@ -1,28 +0,0 @@ -/* C11 threads mutex timed lock implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -mtx_timedlock (mtx_t *restrict mutex, - const struct timespec *restrict time_point) -{ - int err_code = __pthread_mutex_timedlock ((pthread_mutex_t *)mutex, - time_point); - return thrd_err_map (err_code); -} diff --git a/nptl/mtx_trylock.c b/nptl/mtx_trylock.c deleted file mode 100644 index 7ffcbc1e93..0000000000 --- a/nptl/mtx_trylock.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 threads mutex try lock implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -mtx_trylock (mtx_t *mutex) -{ - int err_code = __pthread_mutex_trylock ((pthread_mutex_t *) mutex); - return thrd_err_map (err_code); -} diff --git a/nptl/mtx_unlock.c b/nptl/mtx_unlock.c deleted file mode 100644 index ebb0cd633b..0000000000 --- a/nptl/mtx_unlock.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 threads mutex unlock implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -mtx_unlock (mtx_t *mutex) -{ - int err_code = __pthread_mutex_unlock ((pthread_mutex_t *) mutex); - return thrd_err_map (err_code); -} diff --git a/nptl/thrd_create.c b/nptl/thrd_create.c deleted file mode 100644 index 8423ffc805..0000000000 --- a/nptl/thrd_create.c +++ /dev/null @@ -1,30 +0,0 @@ -/* C11 threads thread creation implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -thrd_create (thrd_t *thr, thrd_start_t func, void *arg) -{ - _Static_assert (sizeof (thrd_t) == sizeof (pthread_t), - "sizeof (thrd_t) != sizeof (pthread_t)"); - - int err_code = __pthread_create_2_1 (thr, ATTR_C11_THREAD, - (void* (*) (void*))func, arg); - return thrd_err_map (err_code); -} diff --git a/nptl/thrd_detach.c b/nptl/thrd_detach.c deleted file mode 100644 index 8ddc2e8477..0000000000 --- a/nptl/thrd_detach.c +++ /dev/null @@ -1,28 +0,0 @@ -/* C11 threads thread detach implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -thrd_detach (thrd_t thr) -{ - int err_code; - - err_code = __pthread_detach (thr); - return thrd_err_map (err_code); -} diff --git a/nptl/thrd_equal.c b/nptl/thrd_equal.c deleted file mode 100644 index 41211d3ef9..0000000000 --- a/nptl/thrd_equal.c +++ /dev/null @@ -1,25 +0,0 @@ -/* C11 threads thread equality check implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -thrd_equal (thrd_t lhs, thrd_t rhs) -{ - return lhs == rhs; -} diff --git a/nptl/thrd_exit.c b/nptl/thrd_exit.c deleted file mode 100644 index d9ad207baa..0000000000 --- a/nptl/thrd_exit.c +++ /dev/null @@ -1,25 +0,0 @@ -/* C11 threads thread exit implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -_Noreturn void -thrd_exit (int res) -{ - __pthread_exit ((void*)(uintptr_t) res); -} diff --git a/nptl/thrd_join.c b/nptl/thrd_join.c deleted file mode 100644 index 0c482959d5..0000000000 --- a/nptl/thrd_join.c +++ /dev/null @@ -1,30 +0,0 @@ -/* C11 threads thread join implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -thrd_join (thrd_t thr, int *res) -{ - void *pthread_res; - int err_code = __pthread_join (thr, &pthread_res); - if (res) - *res = (int) (uintptr_t) pthread_res; - - return thrd_err_map (err_code); -} diff --git a/nptl/thrd_priv.h b/nptl/thrd_priv.h deleted file mode 100644 index d22ad6f632..0000000000 --- a/nptl/thrd_priv.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Internal C11 threads definitions. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#ifndef THRD_PRIV_H -# define THRD_PRIV_H - -#include <features.h> -#include <threads.h> -#include <errno.h> -#include "pthreadP.h" /* For pthread_{mutex,cond}_t definitions. */ - -static __always_inline int -thrd_err_map (int err_code) -{ - switch (err_code) - { - case 0: - return thrd_success; - case ENOMEM: - return thrd_nomem; - case ETIMEDOUT: - return thrd_timedout; - case EBUSY: - return thrd_busy; - default: - return thrd_error; - } -} - -#endif diff --git a/nptl/thrd_sleep.c b/nptl/thrd_sleep.c deleted file mode 100644 index c9805d5fd1..0000000000 --- a/nptl/thrd_sleep.c +++ /dev/null @@ -1,36 +0,0 @@ -/* C11 threads thread sleep implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <time.h> -#include <sysdep-cancel.h> - -#include "thrd_priv.h" - -int -thrd_sleep (const struct timespec* time_point, struct timespec* remaining) -{ - int ret = __clock_nanosleep (CLOCK_REALTIME, 0, time_point, remaining); - /* C11 states thrd_sleep function returns -1 if it has been interrupted - by a signal, or a negative value if it fails. */ - switch (ret) - { - case 0: return 0; - case EINTR: return -1; - default: return -2; - } -} diff --git a/nptl/tss_create.c b/nptl/tss_create.c deleted file mode 100644 index 4e170dd4fc..0000000000 --- a/nptl/tss_create.c +++ /dev/null @@ -1,33 +0,0 @@ -/* C11 threads thread-specific creation implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -tss_create (tss_t *tss_id, tss_dtor_t destructor) -{ - _Static_assert (sizeof (tss_t) == sizeof (pthread_key_t), - "sizeof (tss_t) != sizeof (pthread_key_t)"); -#ifdef PTHREAD_DESTRUCTOR_ITERATIONS - _Static_assert (TSS_DTOR_ITERATIONS == PTHREAD_DESTRUCTOR_ITERATIONS, - "TSS_DTOR_ITERATIONS != PTHREAD_DESTRUCTOR_ITERATIONS"); -#endif - - int err_code = __pthread_key_create (tss_id, destructor); - return thrd_err_map (err_code); -} diff --git a/nptl/tss_delete.c b/nptl/tss_delete.c deleted file mode 100644 index 38570ea100..0000000000 --- a/nptl/tss_delete.c +++ /dev/null @@ -1,25 +0,0 @@ -/* C11 threads thread-specific delete implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -void -tss_delete (tss_t tss_id) -{ - __pthread_key_delete (tss_id); -} diff --git a/nptl/tss_get.c b/nptl/tss_get.c deleted file mode 100644 index f8300b7b84..0000000000 --- a/nptl/tss_get.c +++ /dev/null @@ -1,25 +0,0 @@ -/* C11 threads thread-specific get implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -void * -tss_get (tss_t tss_id) -{ - return __pthread_getspecific (tss_id); -} diff --git a/nptl/tss_set.c b/nptl/tss_set.c deleted file mode 100644 index b21b6c2647..0000000000 --- a/nptl/tss_set.c +++ /dev/null @@ -1,26 +0,0 @@ -/* C11 threads thread-specific set implementation. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include "thrd_priv.h" - -int -tss_set (tss_t tss_id, void *val) -{ - int err_code = __pthread_setspecific (tss_id, val); - return thrd_err_map (err_code); -} diff --git a/nptl/tst-call-once.c b/nptl/tst-call-once.c deleted file mode 100644 index c198233e8d..0000000000 --- a/nptl/tst-call-once.c +++ /dev/null @@ -1,66 +0,0 @@ -/* C11 threads call_once test. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Flag that controls the first thread access. */ -static once_flag flag = ONCE_FLAG_INIT; - -static int value = 0; - -static void -do_once (void) -{ - value++; -} - -static int -func (void* data) -{ - call_once (&flag, do_once); - thrd_exit (thrd_success); -} - -#define N 20 - -int -do_test (void) -{ - thrd_t ids[N]; - - for (int i = 0; i < N; ++i) - { - if (thrd_create (&ids[i], func, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - } - - /* Join threads. */ - for (int i = 0; i < N; ++i) - { - if (thrd_join (ids[i], NULL) != thrd_success) - FAIL_EXIT1 ("thrd_join failed"); - } - - return (value != 1); -} - -#include <support/test-driver.c> diff --git a/nptl/tst-cnd-basic.c b/nptl/tst-cnd-basic.c deleted file mode 100644 index 041762ae35..0000000000 --- a/nptl/tst-cnd-basic.c +++ /dev/null @@ -1,80 +0,0 @@ -/* C11 threads condition variable tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Shared condition variable between child and parent. */ -static cnd_t cond; - -/* Mutex needed to signal and wait threads. */ -static mtx_t mutex; - -static int -signal_parent (void) -{ - /* Acquire the lock so that cnd_signal does not run until - cnd_timedwait has been called. */ - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - if (cnd_signal (&cond) != thrd_success) - FAIL_EXIT1 ("cnd_signal"); - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock"); - - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - thrd_t id; - - if (cnd_init (&cond) != thrd_success) - FAIL_EXIT1 ("cnd_init failed"); - if (mtx_init (&mutex, mtx_plain) != thrd_success) - FAIL_EXIT1 ("mtx_init failed"); - - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - - if (thrd_create (&id, (thrd_start_t) signal_parent, NULL) - != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - if (cnd_wait (&cond, &mutex) != thrd_success) - FAIL_EXIT1 ("cnd_wait failed"); - - /* Joining is not mandatory here, but still done to assure child thread - ends correctly. */ - if (thrd_join (id, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_join failed"); - - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock"); - - mtx_destroy (&mutex); - cnd_destroy (&cond); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-cnd-broadcast.c b/nptl/tst-cnd-broadcast.c deleted file mode 100644 index ccc8504f6f..0000000000 --- a/nptl/tst-cnd-broadcast.c +++ /dev/null @@ -1,97 +0,0 @@ -/* C11 threads condition broadcast variable tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdbool.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Condition variable where child threads will wait. */ -static cnd_t cond; - -/* Mutex to control wait on cond. */ -static mtx_t mutex; - -/* Number of threads which have entered the cnd_wait region. */ -static unsigned int waiting_threads; - -/* Code executed by each thread. */ -static int -child_wait (void* data) -{ - /* Wait until parent thread sends broadcast here. */ - mtx_lock (&mutex); - ++waiting_threads; - cnd_wait (&cond, &mutex); - mtx_unlock (&mutex); - - thrd_exit (thrd_success); -} - -#define N 5 - -static int -do_test (void) -{ - thrd_t ids[N]; - unsigned char i; - - if (cnd_init (&cond) != thrd_success) - FAIL_EXIT1 ("cnd_init failed"); - if (mtx_init (&mutex, mtx_plain) != thrd_success) - FAIL_EXIT1 ("mtx_init failed"); - - /* Create N new threads. */ - for (i = 0; i < N; ++i) - { - if (thrd_create (&ids[i], child_wait, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - } - - /* Wait for other threads to reach their wait func. */ - while (true) - { - mtx_lock (&mutex); - TEST_VERIFY (waiting_threads <= N); - bool done_waiting = waiting_threads == N; - mtx_unlock (&mutex); - if (done_waiting) - break; - thrd_sleep (&((struct timespec){.tv_nsec = 100 * 1000 * 1000}), NULL); - } - - mtx_lock (&mutex); - if (cnd_broadcast (&cond) != thrd_success) - FAIL_EXIT1 ("cnd_broadcast failed"); - mtx_unlock (&mutex); - - for (i = 0; i < N; ++i) - { - if (thrd_join (ids[i], NULL) != thrd_success) - FAIL_EXIT1 ("thrd_join failed"); - } - - mtx_destroy (&mutex); - cnd_destroy (&cond); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-cnd-timedwait.c b/nptl/tst-cnd-timedwait.c deleted file mode 100644 index 05e3a051a5..0000000000 --- a/nptl/tst-cnd-timedwait.c +++ /dev/null @@ -1,84 +0,0 @@ -/* C11 threads condition timed wait variable tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Shared condition variable between child and parent. */ -static cnd_t cond; - -/* Mutex needed to signal and wait threads. */ -static mtx_t mutex; - -static int -signal_parent (void *arg) -{ - /* Acquire the lock so that cnd_signal does not run until - cnd_timedwait has been called. */ - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - if (cnd_signal (&cond) != thrd_success) - FAIL_EXIT1 ("cnd_signal failed"); - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock"); - - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - thrd_t id; - struct timespec w_time; - - if (cnd_init (&cond) != thrd_success) - FAIL_EXIT1 ("cnd_init failed"); - if (mtx_init (&mutex, mtx_plain) != thrd_success) - FAIL_EXIT1 ("mtx_init failed"); - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - - if (clock_gettime (CLOCK_REALTIME, &w_time) != 0) - FAIL_EXIT1 ("clock_gettime failed"); - - /* This needs to be sufficiently long to prevent the cnd_timedwait - call from timing out. */ - w_time.tv_sec += 3600; - - if (thrd_create (&id, signal_parent, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - if (cnd_timedwait (&cond, &mutex, &w_time) != thrd_success) - FAIL_EXIT1 ("cnd_timedwait failed"); - - if (thrd_join (id, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_join failed"); - - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock"); - - mtx_destroy (&mutex); - cnd_destroy (&cond); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-mtx-basic.c b/nptl/tst-mtx-basic.c deleted file mode 100644 index 1e3d809bd0..0000000000 --- a/nptl/tst-mtx-basic.c +++ /dev/null @@ -1,73 +0,0 @@ -/* C11 threads basic mutex tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Shared mutex between child and parent. */ -static mtx_t mutex; - -/* Shared counter to check possible race conditions. */ -static int counter; - -static int -child_add (void *arg) -{ - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - - counter++; - - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock failed"); - - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - mtx_init (&mutex, mtx_plain); - - thrd_t id; - if (thrd_create (&id, child_add, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - - counter++; - - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock failed"); - - if (thrd_join (id, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_join failed"); - - if (counter != 2) - FAIL_EXIT1 ("counter (%d) != 2", counter); - - mtx_destroy (&mutex); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-mtx-recursive.c b/nptl/tst-mtx-recursive.c deleted file mode 100644 index 6b471ac724..0000000000 --- a/nptl/tst-mtx-recursive.c +++ /dev/null @@ -1,45 +0,0 @@ -/* C11 threads recursive mutex tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -static int -do_test (void) -{ - static mtx_t mutex; - - if (mtx_init (&mutex, mtx_recursive) != thrd_success) - FAIL_EXIT1 ("mtx_init failed"); - - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - - /* Lock mutex second time, if not recursive should deadlock. */ - if (mtx_lock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_lock failed"); - - mtx_destroy (&mutex); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-mtx-timedlock.c b/nptl/tst-mtx-timedlock.c deleted file mode 100644 index 21c73a3d60..0000000000 --- a/nptl/tst-mtx-timedlock.c +++ /dev/null @@ -1,103 +0,0 @@ -/* C11 threads timed mutex tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Shared mutex between child and parent. */ -static mtx_t mutex; - -/* Shared counter to check possible race conditions. */ -static char shrd_counter; - -/* Maximum amount of time waiting for mutex. */ -static struct timespec wait_time; - -/* Function to choose an action to do, depending on mtx_timedlock - return value. */ -static inline void -choose_action (int action, char* thread_name) -{ - switch (action) - { - case thrd_success: - ++shrd_counter; - - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock failed"); - break; - - case thrd_timedout: - break; - - case thrd_error: - FAIL_EXIT1 ("%s lock error", thread_name); - break; - } -} - -static int -child_add (void *arg) -{ - char child_name[] = "child"; - - /* Try to lock mutex. */ - choose_action (mtx_timedlock (&mutex, &wait_time), child_name); - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - thrd_t id; - char parent_name[] = "parent"; - - if (mtx_init (&mutex, mtx_timed) != thrd_success) - FAIL_EXIT1 ("mtx_init failed"); - - if (clock_gettime (CLOCK_REALTIME, &wait_time) != 0) - FAIL_EXIT1 ("clock_gettime failed"); - /* Tiny amount of time, to assure that if any thread finds it busy. - It will receive thrd_timedout. */ - wait_time.tv_nsec += 1; - if (wait_time.tv_nsec == 1000 * 1000 * 1000) - { - wait_time.tv_sec += 1; - wait_time.tv_nsec = 0; - } - - if (thrd_create (&id, child_add, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - choose_action (mtx_timedlock (&mutex, &wait_time), parent_name); - - if (thrd_join (id, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_join failed"); - - if (shrd_counter != 2 && shrd_counter != 1) - FAIL_EXIT1 ("shrd_counter != {1,2} (%d)", shrd_counter); - - mtx_destroy (&mutex); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-mtx-trylock.c b/nptl/tst-mtx-trylock.c deleted file mode 100644 index dcb7a5407b..0000000000 --- a/nptl/tst-mtx-trylock.c +++ /dev/null @@ -1,90 +0,0 @@ -/* C11 threads trylock mutex tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Shared mutex between child and parent. */ -static mtx_t mutex; - -/* Shared counter to check possible race conditions. */ -static char shrd_counter; - -/* Function to choose an action to do, depending on mtx_trylock - return value. */ -static inline void -choose_action (int action, char* thread_name) -{ - switch (action) - { - case thrd_success: - ++shrd_counter; - - if (mtx_unlock (&mutex) != thrd_success) - FAIL_EXIT1 ("mtx_unlock failed"); - break; - - case thrd_busy: - break; - - case thrd_error: - FAIL_EXIT1 ("%s lock error", thread_name); - break; - } -} - -static int -child_add (void *arg) -{ - char child_name[] = "child"; - - /* Try to lock mutex. */ - choose_action (mtx_trylock (&mutex), child_name); - - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - thrd_t id; - char parent_name[] = "parent"; - - if (mtx_init (&mutex, mtx_timed) != thrd_success) - FAIL_EXIT1 ("mtx_init failed"); - - if (thrd_create (&id, child_add, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - choose_action (mtx_trylock (&mutex), parent_name); - - if (thrd_join (id, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_join failed"); - - if (shrd_counter != 2 && shrd_counter != 1) - FAIL_EXIT1 ("shrd_counter != {1,2} (%d)", shrd_counter); - - mtx_destroy (&mutex); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-thrd-detach.c b/nptl/tst-thrd-detach.c deleted file mode 100644 index 53be296f97..0000000000 --- a/nptl/tst-thrd-detach.c +++ /dev/null @@ -1,52 +0,0 @@ -/* C11 threads thread detach tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <time.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -static int -detach_thrd (void *arg) -{ - if (thrd_detach (thrd_current ()) != thrd_success) - FAIL_EXIT1 ("thrd_detach failed"); - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - thrd_t id; - - /* Create new thread. */ - if (thrd_create (&id, detach_thrd, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - /* Give some time so the thread can finish. */ - thrd_sleep (&(struct timespec) {.tv_sec = 2}, NULL); - - if (thrd_join (id, NULL) == thrd_success) - FAIL_EXIT1 ("thrd_join succeed where it should fail"); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-thrd-sleep.c b/nptl/tst-thrd-sleep.c deleted file mode 100644 index 39d5fc7079..0000000000 --- a/nptl/tst-thrd-sleep.c +++ /dev/null @@ -1,51 +0,0 @@ -/* C11 threads thread sleep tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <time.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -static int -sleep_thrd (void *arg) -{ - struct timespec const *tl = (struct timespec const *) arg; - if (thrd_sleep (tl, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_sleep failed"); - - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - thrd_t id; - struct timespec wait_time = {.tv_sec = 3}; - - if (thrd_create (&id, sleep_thrd, (void *) (&wait_time)) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - if (thrd_join (id, NULL) != thrd_success) - FAIL_EXIT1 ("thrd failed"); - - return 0; -} - -#include <support/test-driver.c> diff --git a/nptl/tst-tss-basic.c b/nptl/tst-tss-basic.c deleted file mode 100644 index 3b06abc5cf..0000000000 --- a/nptl/tst-tss-basic.c +++ /dev/null @@ -1,75 +0,0 @@ -/* C11 threads specific storage tests. - Copyright (C) 2018-2020 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <https://www.gnu.org/licenses/>. */ - -#include <threads.h> -#include <stdio.h> -#include <unistd.h> - -#include <support/check.h> - -/* Thread specific storage. */ -static tss_t key; - -#define TSS_VALUE (void*) 0xFF - -static int -tss_thrd (void *arg) -{ - if (tss_create (&key, NULL) != thrd_success) - FAIL_EXIT1 ("tss_create failed"); - - if (tss_set (key, TSS_VALUE)) - FAIL_EXIT1 ("tss_set failed"); - - void *value = tss_get (key); - if (value == 0) - FAIL_EXIT1 ("tss_get failed"); - if (value != TSS_VALUE) - FAIL_EXIT1 ("tss_get returned %p, expected %p", value, TSS_VALUE); - - thrd_exit (thrd_success); -} - -static int -do_test (void) -{ - /* Setting an invalid key should return an error. */ - if (tss_set (key, TSS_VALUE) == thrd_success) - FAIL_EXIT1 ("tss_set succeed where it should have failed"); - - if (tss_create (&key, NULL) != thrd_success) - FAIL_EXIT1 ("tss_create failed"); - - thrd_t id; - if (thrd_create (&id, tss_thrd, NULL) != thrd_success) - FAIL_EXIT1 ("thrd_create failed"); - - if (thrd_join (id, NULL) != thrd_success) - FAIL_EXIT1 ("thrd failed"); - - /* The value set in tss_thrd should not be visible here. */ - void *value = tss_get (key); - if (value != 0) - FAIL_EXIT1 ("tss_get succeed where it should have failed"); - - tss_delete (key); - - return 0; -} - -#include <support/test-driver.c> |