This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC] Add C11 threads.h support.


Dear glibc developers,

As I am preparing what I think that could be my last patch to have C11
threads.h working, I still have a couple doubts to be solved.

First, I would like any of you to review this patch and let me know if
my approach is correct, by separating types in bits/threadstypes.h
from functions in include/threads.h.

Second, I have noticed that there are files that I haven't updated,
that I think that I should. Those files are libpthread.abilist, and I
don't know how should I do it. Should I do it manually? Or is there a
script to get the symbols from the library once it's compiled.

Thanks for your time.
Cheers.

-- 
Juan Manuel Torres Palma.
Computer Science Student at Universidad de Granada.
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.

diff --git a/bits/threadstypes.h b/bits/threadstypes.h
new file mode 100644
index 0000000..cd9f647
--- /dev/null
+++ b/bits/threadstypes.h
@@ -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 */
diff --git a/include/stdc-predef.h b/include/stdc-predef.h
index e5f1139..1a5d899 100644
--- a/include/stdc-predef.h
+++ b/include/stdc-predef.h
@@ -58,7 +58,5 @@
    published.  */
 #define __STDC_ISO_10646__		201304L
 
-/* We do not support C11 <threads.h>.  */
-#define __STDC_NO_THREADS__		1
 
 #endif
diff --git a/include/threads.h b/include/threads.h
new file mode 100644
index 0000000..465ab08
--- /dev/null
+++ b/include/threads.h
@@ -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 */
diff --git a/nptl/Makefile b/nptl/Makefile
index 530d14b..ea67f6f 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -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 \
diff --git a/nptl/Versions b/nptl/Versions
index 34e4b46..0f59855 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -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;
diff --git a/nptl/__thrd_err_map.h b/nptl/__thrd_err_map.h
new file mode 100644
index 0000000..4a5496b
--- /dev/null
+++ b/nptl/__thrd_err_map.h
@@ -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;
+  }
+}
diff --git a/nptl/call_once.c b/nptl/call_once.c
new file mode 100644
index 0000000..03d483a
--- /dev/null
+++ b/nptl/call_once.c
@@ -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);
+}
diff --git a/nptl/cnd_broadcast.c b/nptl/cnd_broadcast.c
new file mode 100644
index 0000000..9aa3e6c
--- /dev/null
+++ b/nptl/cnd_broadcast.c
@@ -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);
+}
diff --git a/nptl/cnd_destroy.c b/nptl/cnd_destroy.c
new file mode 100644
index 0000000..3b2bb81
--- /dev/null
+++ b/nptl/cnd_destroy.c
@@ -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);
+}
diff --git a/nptl/cnd_init.c b/nptl/cnd_init.c
new file mode 100644
index 0000000..1ae5af8
--- /dev/null
+++ b/nptl/cnd_init.c
@@ -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);
+}
diff --git a/nptl/cnd_signal.c b/nptl/cnd_signal.c
new file mode 100644
index 0000000..16e154f
--- /dev/null
+++ b/nptl/cnd_signal.c
@@ -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);
+}
diff --git a/nptl/cnd_timedwait.c b/nptl/cnd_timedwait.c
new file mode 100644
index 0000000..db8c030
--- /dev/null
+++ b/nptl/cnd_timedwait.c
@@ -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);
+}
diff --git a/nptl/cnd_wait.c b/nptl/cnd_wait.c
new file mode 100644
index 0000000..f13b31d
--- /dev/null
+++ b/nptl/cnd_wait.c
@@ -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);
+}
diff --git a/nptl/mtx_destroy.c b/nptl/mtx_destroy.c
new file mode 100644
index 0000000..cc827dd
--- /dev/null
+++ b/nptl/mtx_destroy.c
@@ -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);
+}
diff --git a/nptl/mtx_init.c b/nptl/mtx_init.c
new file mode 100644
index 0000000..3d0d54d
--- /dev/null
+++ b/nptl/mtx_init.c
@@ -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);
+}
diff --git a/nptl/mtx_lock.c b/nptl/mtx_lock.c
new file mode 100644
index 0000000..d63045a
--- /dev/null
+++ b/nptl/mtx_lock.c
@@ -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);
+}
diff --git a/nptl/mtx_timedlock.c b/nptl/mtx_timedlock.c
new file mode 100644
index 0000000..6e1c8cc
--- /dev/null
+++ b/nptl/mtx_timedlock.c
@@ -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);
+}
diff --git a/nptl/mtx_trylock.c b/nptl/mtx_trylock.c
new file mode 100644
index 0000000..2ab12e5
--- /dev/null
+++ b/nptl/mtx_trylock.c
@@ -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);
+}
diff --git a/nptl/mtx_unlock.c b/nptl/mtx_unlock.c
new file mode 100644
index 0000000..f9cd504
--- /dev/null
+++ b/nptl/mtx_unlock.c
@@ -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);
+}
+
diff --git a/nptl/thrd_create.c b/nptl/thrd_create.c
new file mode 100644
index 0000000..88c8a65
--- /dev/null
+++ b/nptl/thrd_create.c
@@ -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);
+}
+
diff --git a/nptl/thrd_current.c b/nptl/thrd_current.c
new file mode 100644
index 0000000..7cdb39a
--- /dev/null
+++ b/nptl/thrd_current.c
@@ -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 ();
+}
diff --git a/nptl/thrd_detach.c b/nptl/thrd_detach.c
new file mode 100644
index 0000000..3563908
--- /dev/null
+++ b/nptl/thrd_detach.c
@@ -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);
+}
diff --git a/nptl/thrd_equal.c b/nptl/thrd_equal.c
new file mode 100644
index 0000000..26587c4
--- /dev/null
+++ b/nptl/thrd_equal.c
@@ -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);
+}
diff --git a/nptl/thrd_exit.c b/nptl/thrd_exit.c
new file mode 100644
index 0000000..5c6fa5a
--- /dev/null
+++ b/nptl/thrd_exit.c
@@ -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);
+}
diff --git a/nptl/thrd_join.c b/nptl/thrd_join.c
new file mode 100644
index 0000000..3fe034a
--- /dev/null
+++ b/nptl/thrd_join.c
@@ -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);
+}
diff --git a/nptl/thrd_sleep.c b/nptl/thrd_sleep.c
new file mode 100644
index 0000000..460c3ad
--- /dev/null
+++ b/nptl/thrd_sleep.c
@@ -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);
+}
diff --git a/nptl/thrd_yield.c b/nptl/thrd_yield.c
new file mode 100644
index 0000000..30d3852
--- /dev/null
+++ b/nptl/thrd_yield.c
@@ -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 ();
+}
diff --git a/nptl/tss_create.c b/nptl/tss_create.c
new file mode 100644
index 0000000..ad85348
--- /dev/null
+++ b/nptl/tss_create.c
@@ -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);
+}
diff --git a/nptl/tss_delete.c b/nptl/tss_delete.c
new file mode 100644
index 0000000..9b912c1
--- /dev/null
+++ b/nptl/tss_delete.c
@@ -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);
+}
diff --git a/nptl/tss_get.c b/nptl/tss_get.c
new file mode 100644
index 0000000..e4fa7b1
--- /dev/null
+++ b/nptl/tss_get.c
@@ -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);
+}
diff --git a/nptl/tss_set.c b/nptl/tss_set.c
new file mode 100644
index 0000000..892cbb8
--- /dev/null
+++ b/nptl/tss_set.c
@@ -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);
+}

Attachment: ChangeLog-0003
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]