commit f3b281bfa2b5d3ec80b8a1ba9988fc1dbf45c3a1
Author: Juan Manuel Torres Palma <jmtorrespalma@gmail.com>
Date: Fri Jun 26 18:43:32 2015 +0200
Add C11 threads.h support.
This patch adds complete support for header threads.h including all
functions and types as specified in C11 standard (ISO/IEC 9899:2011).
All functions and types are based on POSIX threads to simplify
implementation and design.
new file mode 100644
@@ -0,0 +1,69 @@
+/* Copyright (C) 2002-2015 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
+ <http://www.gnu.org/licenses/>. */
+
+
+/* Declaration of C11 threads.h types. All of the types are based
+ on pthread types to ease implementation and compatibility.
+ Most of these types can be consulted in Linux Standard Base
+ Specifications. */
+
+#ifndef _BITS_THREADSTYPES_H
+# define _BITS_THREADSTYPES_H 1
+
+# include <bits/thread-shared-types.h>
+
+# define ONCE_FLAG_INIT 0
+# define thread_local _Thread_local
+# define TSS_DTOR_ITERATIONS 4
+
+typedef unsigned long int thrd_t; /* Based on pthread_t */
+typedef int once_flag; /* Based on pthread_once_t */
+typedef unsigned int tss_t; /* Based on pthread_key_t */
+typedef int (*thrd_start_t) (void*);
+typedef void (*tss_dtor_t) (void*);
+
+/* Exit and error codes */
+enum
+{
+ thrd_success = 0,
+ thrd_busy = 1,
+ thrd_error = 2,
+ thrd_nomem = 3,
+ thrd_timedout = 4
+};
+
+/* Kinds of mutexes */
+enum
+{
+ mtx_plain = 0,
+ mtx_recursive = 1,
+ mtx_timed = 2
+};
+
+/* Definition of mtx_t based on pthread_mutex_t. */
+typedef union
+{
+ __PTHREAD_MUTEX_T_CONTENT
+} mtx_t;
+
+/* Definition of cnd_t based on pthread_cond_t. */
+typedef union
+{
+ __PTHREAD_COND_T_CONTENT
+} cnd_t;
+
+#endif /* bits/threadstypes.h */
@@ -58,7 +58,5 @@
published. */
#define __STDC_ISO_10646__ 201304L
-/* We do not support C11 <threads.h>. */
-#define __STDC_NO_THREADS__ 1
#endif
new file mode 100644
@@ -0,0 +1,85 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+/*
+ * ISO C11 Standard: 7.26
+ * Thread support library <threads.h>
+ */
+
+
+#ifndef _THREADS_H
+#define _THREADS_H 1
+
+#include <features.h>
+
+#ifndef __STDC_NO_THREADS__
+
+# include <time.h>
+# include <bits/threadstypes.h>
+
+//#if ( defined __STDC_VERSION__ && __STDC_VERSION__ < 201112L )
+//# error "<threads.h> requires ISO C11 mode"
+//#else
+
+# ifdef __cplusplus
+__BEGIN_DECLS
+# endif
+
+/* Threads functions */
+extern int thrd_create (thrd_t *thr, thrd_start_t func, void *arg );
+extern int thrd_equal (thrd_t lhs, thrd_t rhs);
+extern thrd_t thrd_current (void);
+extern int thrd_sleep (const struct timespec *time_point,
+ struct timespec *remaining);
+extern _Noreturn void thrd_exit (int res);
+extern int thrd_detach (thrd_t thr);
+extern int thrd_join (thrd_t thr, int *res);
+extern void thrd_yield (void);
+
+/* Mutex functions */
+extern int mtx_init (mtx_t *mutex, int type);
+extern int mtx_lock (mtx_t *mutex);
+extern int mtx_timedlock (mtx_t *__restrict mutex,
+ const struct timespec *__restrict time_point);
+extern int mtx_trylock (mtx_t *mutex);
+extern int mtx_unlock (mtx_t *mutex);
+extern void mtx_destroy (mtx_t *mutex);
+extern void call_once (once_flag *flag, void (*func)(void));
+
+/* Condition variable functions */
+extern int cnd_init (cnd_t *cond);
+extern int cnd_signal (cnd_t *cond);
+extern int cnd_broadcast (cnd_t *cond);
+extern int cnd_wait (cnd_t *cond, mtx_t *mutex);
+extern int cnd_timedwait (cnd_t *__restrict cond,
+ mtx_t *__restrict mutex,
+ const struct timespec *__restrict time_point);
+extern void cnd_destroy (cnd_t *cond);
+
+/* Thread specific storage functions */
+extern int tss_create (tss_t *tss_id, tss_dtor_t destructor);
+extern void *tss_get (tss_t tss_id);
+extern int tss_set (tss_t tss_id, void *val);
+extern void tss_delete (tss_t tss_id);
+
+# ifdef __cplusplus
+__END_DECLS
+# endif
+
+//#endif /* Version check */
+#endif /* __STDC_NO_THREADS__ */
+#endif /* _THREADS_H */
@@ -22,7 +22,8 @@ subdir := nptl
include ../Makeconfig
-headers := pthread.h semaphore.h bits/semaphore.h
+headers := pthread.h semaphore.h bits/semaphore.h \
+ threads.h bits/threadstypes.h
extra-libs := libpthread
extra-libs-others := $(extra-libs)
@@ -132,7 +133,15 @@ libpthread-routines = nptl-init vars events version pt-interp \
pthread_mutex_getprioceiling \
pthread_mutex_setprioceiling \
pthread_setname pthread_getname \
- pthread_setattr_default_np pthread_getattr_default_np
+ pthread_setattr_default_np pthread_getattr_default_np \
+ thrd_create thrd_current thrd_detach thrd_equal \
+ thrd_exit thrd_join thrd_sleep thrd_yield \
+ call_once cnd_broadcast cnd_destroy cnd_init \
+ cnd_signal cnd_timedwait cnd_wait \
+ mtx_destroy mtx_init mtx_lock mtx_timedlock \
+ mtx_trylock mtx_unlock \
+ tss_create tss_delete tss_get tss_set
+
# pthread_setuid pthread_seteuid pthread_setreuid \
# pthread_setresuid \
# pthread_setgid pthread_setegid pthread_setregid \
@@ -267,7 +267,19 @@ libpthread {
}
GLIBC_2.22 {
- }
+ thrd_create; thrd_current;
+ thrd_detach; thrd_equal;
+ thrd_exit; thrd_join;
+ thrd_sleep; thrd_yield;
+ call_once; cnd_broadcast;
+ cnd_destroy; cnd_init;
+ cnd_signal; cnd_timedwait;
+ cnd_wait; mtx_destroy;
+ mtx_init; mtx_lock;
+ mtx_timedlock; mtx_trylock;
+ mtx_unlock; tss_create;
+ tss_delete; tss_get; tss_set;
+ };
GLIBC_PRIVATE {
__pthread_initialize_minimal;
new file mode 100644
@@ -0,0 +1,43 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include <errno.h>
+
+/* Maps pthread error codes with thrd error codes.
+ Defined as inline because it's a common function used
+ by most of threads.h functions, so we avoid code duplication
+ with a small inline function. */
+
+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;
+ }
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+void call_once (once_flag *flag, void (*func)(void))
+{
+ pthread_once (flag, func);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int cnd_broadcast (cnd_t *cond)
+{
+ int err_code = pthread_cond_broadcast ((pthread_cond_t*) cond);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+void cnd_destroy (cnd_t *cond)
+{
+ pthread_cond_destroy ((pthread_cond_t *) cond);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int cnd_init (cnd_t *cond)
+{
+ int err_code = pthread_cond_init ((pthread_cond_t *)cond, NULL);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int cnd_signal (cnd_t *cond)
+{
+ int err_code = pthread_cond_signal ((pthread_cond_t *) cond);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+
+#include <threads.h>
+#include "__thrd_err_map.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);
+}
new file mode 100644
@@ -0,0 +1,26 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.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);
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+void mtx_destroy (mtx_t *mutex)
+{
+ pthread_mutex_destroy ((pthread_mutex_t *) mutex);
+}
new file mode 100644
@@ -0,0 +1,51 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+
+int mtx_init (mtx_t *mutex, int type)
+{
+ pthread_mutexattr_t config;
+ int pthd_type;
+ int err_code;
+
+ /* Initialize config */
+ pthread_mutexattr_init (&config);
+
+ /* Match types for mutex creation */
+ switch (type)
+ {
+ case mtx_plain | mtx_recursive:
+ case mtx_timed | mtx_recursive:
+ pthd_type = PTHREAD_MUTEX_RECURSIVE;
+ break;
+ case mtx_plain:
+ case mtx_timed: /* No difference between both in standard */
+ default:
+ pthd_type = PTHREAD_MUTEX_DEFAULT;
+ break;
+ }
+
+ /* Set type of mutex */
+ pthread_mutexattr_settype (&config, pthd_type);
+ /* Initialize mutex with config */
+ err_code = pthread_mutex_init ((pthread_mutex_t *) mutex, &config);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int mtx_lock (mtx_t *mutex)
+{
+ int err_code = pthread_mutex_lock ((pthread_mutex_t *) mutex);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include <time.h>
+#include "__thrd_err_map.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);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int mtx_trylock (mtx_t *mutex)
+{
+ int err_code = pthread_mutex_trylock ((pthread_mutex_t *) mutex);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,26 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int mtx_unlock (mtx_t *mutex)
+{
+ int err_code = pthread_mutex_unlock ((pthread_mutex_t *) mutex);
+ return __thrd_err_map (err_code);
+}
+
new file mode 100644
@@ -0,0 +1,27 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int thrd_create (thrd_t *thr, thrd_start_t func, void *arg)
+{
+ int err_code = pthread_create (thr, NULL, (void* (*) (void*))func, arg);
+ return __thrd_err_map (err_code);
+}
+
new file mode 100644
@@ -0,0 +1,24 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+thrd_t thrd_current ()
+{
+ return pthread_self ();
+}
new file mode 100644
@@ -0,0 +1,27 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int thrd_detach (thrd_t thr)
+{
+ int err_code;
+
+ err_code = pthread_detach (thr);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int thrd_equal (thrd_t lhs, thrd_t rhs)
+{
+ return pthread_equal (lhs, rhs);
+}
new file mode 100644
@@ -0,0 +1,29 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include <stdint.h>
+#include "__thrd_err_map.h"
+
+_Noreturn void thrd_exit (int res)
+{
+ /* We need to cast an int to void pointer */
+ uintptr_t aux_pointer;
+
+ aux_pointer = res;
+ pthread_exit ((void*) aux_pointer);
+}
new file mode 100644
@@ -0,0 +1,43 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int thrd_join (thrd_t thr, int *res)
+{
+ int err_code;
+ uintptr_t aux_p;
+
+ /** We have to cast the pointer res to a void** so the
+ * pthread function can modify it. In case we don't want
+ * to store the value returned, we have to send a NULL
+ * pointer to pthread_join, instead of the stack value
+ * where the pointer is currently stored
+ */
+
+ if (res != NULL)
+ {
+ err_code = pthread_join (thr,(void*) &aux_p);
+ *res = (int)aux_p;
+
+ }else{
+ err_code = pthread_join (thr, NULL);
+ }
+
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,27 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include <time.h>
+
+int thrd_sleep (const struct timespec* time_point,
+ struct timespec* remaining)
+{
+
+ /* Returns 0 if success, -1 if interrupted and other if error */
+ return __nanosleep (time_point, remaining);
+}
new file mode 100644
@@ -0,0 +1,24 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+void thrd_yield ()
+{
+ sched_yield ();
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int tss_create (tss_t *tss_id, tss_dtor_t destructor)
+{
+ int err_code = pthread_key_create (tss_id, destructor);
+ return __thrd_err_map (err_code);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+void tss_delete (tss_t tss_id)
+{
+ pthread_key_delete (tss_id);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+void *tss_get (tss_t tss_id)
+{
+ /* Returns NULL if not successful or the pointer if success */
+ return pthread_getspecific (tss_id);
+}
new file mode 100644
@@ -0,0 +1,25 @@
+/* Copyright (C) 2015 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <threads.h>
+#include "__thrd_err_map.h"
+
+int tss_set (tss_t tss_id, void *val)
+{
+ int err_code = pthread_setspecific (tss_id, val);
+ return __thrd_err_map (err_code);
+}