pthread: Add pthread_getthreadid_np() function, bump __DragonFly_version.
authorImre Vadász <imre@vdsz.com>
Sat, 15 Jul 2017 09:13:36 +0000 (11:13 +0200)
committerImre Vadász <imre@vdsz.com>
Sat, 15 Jul 2017 20:58:36 +0000 (22:58 +0200)
Using pthread_getthreadid_np() can directly use the thread-ID value that is
already cached in the pthread_t struct.

Partly Taken-From: FreeBSD

14 files changed:
include/pthread_np.h
lib/libc/gen/Symbol.map
lib/libc/gen/_pthread_stubs.c
lib/libc/include/namespace.h
lib/libc/include/un-namespace.h
lib/libc_r/uthread/Makefile.inc
lib/libc_r/uthread/uthread_getthreadid_np.c [new file with mode: 0644]
lib/libpthread/Makefile
lib/libpthread/pthread_getthreadid_np.3 [new file with mode: 0644]
lib/libthread_xu/pthread.map
lib/libthread_xu/thread/Makefile.inc
lib/libthread_xu/thread/thr_getthreadid_np.c [new file with mode: 0644]
lib/libthread_xu/thread/thr_init.c
sys/sys/param.h

index 354d211..28d0ebb 100644 (file)
@@ -47,6 +47,7 @@ int pthread_attr_getaffinity_np(const pthread_attr_t *, size_t, cpu_set_t *);
 int pthread_attr_setaffinity_np(pthread_attr_t *, size_t, const cpu_set_t *);
 int pthread_attr_setcreatesuspend_np(pthread_attr_t *);
 int pthread_getaffinity_np(pthread_t, size_t, cpu_set_t *);
+int pthread_getthreadid_np(void);
 int pthread_main_np(void);
 int pthread_multi_np(void);
 int pthread_mutexattr_getkind_np(pthread_mutexattr_t);
index 7b2cdde..bdfce2b 100644 (file)
@@ -459,6 +459,11 @@ DF404.0 {
     wordfree;
 };
 
+DF410.0 {
+       /* pthread stubs */
+    pthread_getthreadid_np;
+};
+
 DFprivate_1.0 {
        /* pthread stubs */
     _pthread_atfork;
@@ -516,6 +521,7 @@ DFprivate_1.0 {
     _pthread_getprio;
     _pthread_getschedparam;
     _pthread_getspecific;
+    _pthread_getthreadid_np;
     _pthread_init;
     _pthread_init_early;
     _pthread_join;
index 28a6564..13c0bd0 100644 (file)
@@ -102,6 +102,7 @@ WR(stub_zero, pthread_getconcurrency);
 WR(stub_zero, pthread_getprio);
 WR(stub_zero, pthread_getschedparam);
 WR(stub_null, pthread_getspecific);
+WR(stub_zero, pthread_getthreadid_np);
 WR(stub_empty, pthread_init_early);
 WR(stub_zero, pthread_join);
 WR(stub_zero, pthread_key_create);
index a0f8ce9..e2ad237 100644 (file)
 #define                pthread_getprio                 _pthread_getprio
 #define                pthread_getschedparam           _pthread_getschedparam
 #define                pthread_getspecific             _pthread_getspecific
+#define                pthread_getthreadid_np          _pthread_getthreadid_np
 #define                pthread_join                    _pthread_join
 #define                pthread_key_create              _pthread_key_create
 #define                pthread_key_delete              _pthread_key_delete
index 17989e4..cecfc36 100644 (file)
 #undef         pthread_getprio
 #undef         pthread_getschedparam
 #undef         pthread_getspecific
+#undef         pthread_getthreadid_np
 #undef         pthread_join
 #undef         pthread_key_create
 #undef         pthread_key_delete
index 5d2693e..565ac85 100644 (file)
@@ -72,6 +72,7 @@ SRCS+= \
        uthread_getschedparam.c \
        uthread_getsockname.c \
        uthread_getsockopt.c \
+       uthread_getthreadid_np.c \
        uthread_info.c \
        uthread_init.c \
        uthread_ioctl.c \
diff --git a/lib/libc_r/uthread/uthread_getthreadid_np.c b/lib/libc_r/uthread/uthread_getthreadid_np.c
new file mode 100644 (file)
index 0000000..a5904cf
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2017 Imre Vadász <imre@vdsz.com>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <pthread.h>
+#include <pthread_np.h>
+#include "pthread_private.h"
+
+int
+_pthread_getthreadid_np(void)
+{
+       struct pthread *curthread = _get_curthread();
+       return curthread->uniqueid;
+}
+
+__strong_reference(_pthread_getthreadid_np, pthread_getthreadid_np);
index 924822b..f915fdf 100644 (file)
@@ -30,6 +30,7 @@ MAN+= \
        pthread_equal.3 \
        pthread_exit.3 \
        pthread_getspecific.3 \
+       pthread_getthreadid_np.3 \
        pthread_join.3 \
        pthread_key_create.3 \
        pthread_key_delete.3 \
diff --git a/lib/libpthread/pthread_getthreadid_np.3 b/lib/libpthread/pthread_getthreadid_np.3
new file mode 100644 (file)
index 0000000..003b1ee
--- /dev/null
@@ -0,0 +1,54 @@
+.\" Copyright (c) 2011 Jung-uk Kim <jkim@FreeBSD.org>
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd July 15, 2017
+.Dt PTHREAD_GETTHREADID_NP 3
+.Os
+.Sh NAME
+.Nm pthread_getthreadid_np
+.Nd get the calling thread's integral ID
+.Sh LIBRARY
+.Lb libpthread
+.Sh SYNOPSIS
+.In pthread_np.h
+.Ft int
+.Fn pthread_getthreadid_np void
+.Sh DESCRIPTION
+The
+.Fn pthread_getthreadid_np
+function returns the unique integral ID of the calling thread.
+Its semantics is similar to the AIX's
+.Fn pthread_getthreadid_np
+function.
+.Sh RETURN VALUES
+The
+.Fn pthread_getthreadid_np
+function returns the thread integral ID of the calling thread.
+.Sh ERRORS
+None.
+.Sh SEE ALSO
+.Xr pthread_self 3
+.Sh AUTHORS
+This manual page was written by
+.An Jung-uk Kim Aq Mt jkim@FreeBSD.org .
index 4b1bfe7..e15440e 100644 (file)
@@ -390,3 +390,9 @@ LIBTHREAD_1_1 {
 global:
        ppoll;
 };
+
+LIBTHREAD_1_2 {
+global:
+       _pthread_getthreadid_np;
+       pthread_getthreadid_np;
+};
index 27d0204..af110a1 100644 (file)
@@ -21,6 +21,7 @@ SRCS+= \
        thr_fork.c \
        thr_getprio.c \
        thr_getschedparam.c \
+       thr_getthreadid_np.c \
        thr_info.c \
        thr_init.c \
        thr_join.c \
diff --git a/lib/libthread_xu/thread/thr_getthreadid_np.c b/lib/libthread_xu/thread/thr_getthreadid_np.c
new file mode 100644 (file)
index 0000000..48ba75b
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Imre Vadász <imre@vdsz.com>.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include "namespace.h"
+#include <pthread.h>
+#include <pthread_np.h>
+#include "un-namespace.h"
+
+#include "thr_private.h"
+
+int
+_pthread_getthreadid_np(void)
+{
+       struct pthread *curthread = tls_get_curthread();
+       return curthread->tid;
+}
+
+__strong_reference(_pthread_getthreadid_np, pthread_getthreadid_np);
index 7a3ae5e..d14c621 100644 (file)
@@ -111,6 +111,8 @@ STATIC_LIB_REQUIRE(_pthread_getaffinity_np);
 STATIC_LIB_REQUIRE(_pthread_getprio);
 /* thr_getschedparam.c */
 STATIC_LIB_REQUIRE(_pthread_getschedparam);
+/* thr_getthreadid_np.c */
+STATIC_LIB_REQUIRE(_pthread_getthreadid_np);
 /* thr_info.c */
 STATIC_LIB_REQUIRE(_pthread_set_name_np);
 /* thr_init.c */
index 154351a..4971dbb 100644 (file)
  * 400904 - pad rtstatistics
  * 400905 - PTHREAD_STACK_MIN increase: 1024 => 16384
  * 400906 - lwpid_t >=1, instead of >=0
+ * 400907 - pthread_getthreadid_np()
  */
 #undef __DragonFly_version
-#define __DragonFly_version 400906     /* propagated to newvers */
+#define __DragonFly_version 400907     /* propagated to newvers */
 
 #include <sys/_null.h>