This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v2][PATCH 27/27] Add Infinity notes implementing libpthread::thr_get_state
- From: Gary Benson <gbenson at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Mon, 13 Jun 2016 11:38:31 +0100
- Subject: [RFC v2][PATCH 27/27] Add Infinity notes implementing libpthread::thr_get_state
- Authentication-results: sourceware.org; auth=none
- References: <1465814311-31470-1-git-send-email-gbenson at redhat dot com>
This commit adds the Infinity function libpthread::thr_get_state.
It has no libthread_db equivalent (in libthread_db the state of
a thread is read from the ti_state field of the td_thrinfo_t that
td_thr_get_info fills in).
---
nptl/Makefile | 2 +-
nptl/infinity-thr_get_state.i8 | 58 ++++++++++++++++++++++++++++++++++++
nptl/tst-infinity-thr_get_state.py | 38 +++++++++++++++++++++++
3 files changed, 97 insertions(+), 1 deletions(-)
create mode 100644 nptl/infinity-thr_get_state.i8
create mode 100644 nptl/tst-infinity-thr_get_state.py
diff --git a/nptl/Makefile b/nptl/Makefile
index bdfe656..1c10798 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -140,7 +140,7 @@ libpthread-routines = nptl-init vars events version pt-interp \
ifeq ($(build-infinity),yes)
infinity-routines = infinity-map_lwp2thr infinity-thr_iter \
- infinity-thr_get_lwpid
+ infinity-thr_get_lwpid infinity-thr_get_state
libpthread-routines += $(infinity-routines)
endif
diff --git a/nptl/infinity-thr_get_state.i8 b/nptl/infinity-thr_get_state.i8
new file mode 100644
index 0000000..74b140d
--- /dev/null
+++ b/nptl/infinity-thr_get_state.i8
@@ -0,0 +1,58 @@
+/* Get the state of a thread.
+ Copyright (C) 2016 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 "infinity-nptl.i8"
+
+/* Return the state of a thread. */
+
+define MODULE_NAME::thr_get_state returns td_err_e, td_thr_state_e
+ argument pthread_t descr
+
+ dup
+ beq NULL, fake_descriptor
+
+real_descriptor:
+ add PTHREAD_CANCELHANDLING_OFFSET
+ deref i32
+ goto got_value
+
+fake_descriptor:
+ drop /* descr. */
+ load 0
+ goto got_value
+
+got_value:
+ dup
+ and EXITING_BITMASK
+ bne 0, thread_exiting
+ /* XXX For now there is no way to get more information. */
+ load TD_THR_ACTIVE
+ load TD_OK
+ return
+
+thread_exiting:
+ and TERMINATED_BITMASK
+ bne 0, thread_terminated
+ load TD_THR_UNKNOWN
+ load TD_OK
+ return
+
+thread_terminated:
+ load TD_THR_ZOMBIE
+ load TD_OK
+ return
diff --git a/nptl/tst-infinity-thr_get_state.py b/nptl/tst-infinity-thr_get_state.py
new file mode 100644
index 0000000..2ba3ab6
--- /dev/null
+++ b/nptl/tst-infinity-thr_get_state.py
@@ -0,0 +1,38 @@
+from i8c.runtime import TestCase
+
+TestCase.import_builtin_constants()
+TestCase.import_constants_from("infinity-nptl-constants.h")
+TestCase.import_constants_from("infinity-nptl_db-constants.h")
+
+class TestThrGetState(TestCase):
+ TESTFUNC = "libpthread::thr_get_state(p)ii"
+
+ def __do_test(self, descr, expect_state):
+ result = self.i8ctx.call(self.TESTFUNC, descr)
+ self.assertEqual(len(result), 2)
+ self.assertEqual(result[0], TD_OK)
+ self.assertEqual(result[1], expect_state)
+
+ def test_faked(self):
+ """Test thr_get_state with a faked descriptor"""
+ self.__do_test(NULL, TD_THR_ACTIVE)
+
+ def __do_test_real(self, cancelhandling, expect_state):
+ with self.memory.builder() as mem:
+ descr = mem.alloc()
+ descr.store_i32(PTHREAD_CANCELHANDLING_OFFSET,
+ cancelhandling)
+ self.__do_test(descr, expect_state)
+
+ def test_active(self):
+ """Test thr_get_state with an active thread"""
+ self.__do_test_real(0, TD_THR_ACTIVE)
+
+ def test_exiting(self):
+ """Test thr_get_state with an exiting thread"""
+ self.__do_test_real(EXITING_BITMASK, TD_THR_UNKNOWN)
+
+ def test_exited(self):
+ """Test thr_get_state with an exited thread"""
+ self.__do_test_real(EXITING_BITMASK | TERMINATED_BITMASK,
+ TD_THR_ZOMBIE)
--
1.7.1