[Glibc-bsd-commits] r4607 - in trunk/glibc-ports/fbtl: . sysdeps/pthread
Petr Salinger
ps-guest at alioth.debian.org
Mon Jul 8 12:47:21 UTC 2013
Author: ps-guest
Date: 2013-06-25 07:42:37 +0000 (Tue, 25 Jun 2013)
New Revision: 4607
Modified:
trunk/glibc-ports/fbtl/allocatestack.c
trunk/glibc-ports/fbtl/descr.h
trunk/glibc-ports/fbtl/nptl-init.c
trunk/glibc-ports/fbtl/pthreadP.h
trunk/glibc-ports/fbtl/pthread_join.c
trunk/glibc-ports/fbtl/pthread_timedjoin.c
trunk/glibc-ports/fbtl/pthread_tryjoin.c
trunk/glibc-ports/fbtl/sysdeps/pthread/createthread.c
Log:
do not use MAP_STACK at all, ktid changes part2
Modified: trunk/glibc-ports/fbtl/allocatestack.c
===================================================================
--- trunk/glibc-ports/fbtl/allocatestack.c 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/allocatestack.c 2013-06-25 07:42:37 UTC (rev 4607)
@@ -84,7 +84,17 @@
# define MINIMAL_REST_STACK 4096
#endif
+/*
+ Unfortunately, under FreeBSD mmap fails with addr=NULL, flags=MAP_STACK
+
+ See http://www.freebsd.org/cgi/query-pr.cgi?pr=158755
+
+ do not use MAP_STACK at all
+*/
+#undef MAP_STACK
+
+
/* Newer kernels have the MAP_STACK flag to indicate a mapping is used for
a stack. Use it when possible. */
#ifndef MAP_STACK
@@ -130,7 +140,7 @@
/* Check whether the stack is still used or not. */
-#define FREE_P(descr) ((descr)->tid <= 0)
+#define FREE_P(descr) ((descr)->tid <= KTID_TERMINATED)
static void
Modified: trunk/glibc-ports/fbtl/descr.h
===================================================================
--- trunk/glibc-ports/fbtl/descr.h 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/descr.h 2013-06-25 07:42:37 UTC (rev 4607)
@@ -166,7 +166,21 @@
/* Thread ID - which is also a 'is this thread descriptor (and
therefore stack) used' flag. */
+#if (__BYTE_ORDER == __LITTLE_ENDIAN) || (__WORDSIZE == 32)
+ union {
pid_t tid;
+ long ktid;
+ };
+#else
+#error untested padding layout:
+ union {
+ struct {
+ int __pad_tid;
+ pid_t tid;
+ };
+ long ktid;
+ };
+#endif
/* Process ID - thread group ID in kernel speak. */
pid_t pid;
Modified: trunk/glibc-ports/fbtl/nptl-init.c
===================================================================
--- trunk/glibc-ports/fbtl/nptl-init.c 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/nptl-init.c 2013-06-25 07:42:37 UTC (rev 4607)
@@ -304,10 +304,13 @@
/* Minimal initialization of the thread descriptor. */
struct pthread *pd = THREAD_SELF;
-#if 0
+#if 1
+ pd->pid = __getpid();
+ INLINE_SYSCALL(thr_self, 1, &(pd->ktid));
+#else
INTERNAL_SYSCALL_DECL (err);
pd->pid = pd->tid = INTERNAL_SYSCALL (set_tid_address, err, 1, &pd->tid);
-#endif
+#endif
THREAD_SETMEM (pd, specific[0], &pd->specific_1stblock[0]);
THREAD_SETMEM (pd, user_stack, true);
if (LLL_LOCK_INITIALIZER != 0)
Modified: trunk/glibc-ports/fbtl/pthreadP.h
===================================================================
--- trunk/glibc-ports/fbtl/pthreadP.h 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/pthreadP.h 2013-06-25 07:42:37 UTC (rev 4607)
@@ -197,6 +197,7 @@
/* The library can run in debugging mode where it performs a lot more
tests. */
extern int __pthread_debug attribute_hidden;
+
/** For now disable debugging support. */
#if 0
# define DEBUGGING_P __builtin_expect (__pthread_debug, 0)
@@ -207,8 +208,8 @@
/* Simplified test. This will not catch all invalid descriptors but
is better than nothing. And if the test triggers the thread
descriptor is guaranteed to be invalid. */
-# define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= 0, 0)
-# define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < 0, 0)
+# define INVALID_TD_P(pd) __builtin_expect ((pd)->tid <= KTID_TERMINATED, 0)
+# define INVALID_NOT_TERMINATED_TD_P(pd) __builtin_expect ((pd)->tid < KTID_TERMINATED, 0)
#endif
Modified: trunk/glibc-ports/fbtl/pthread_join.c
===================================================================
--- trunk/glibc-ports/fbtl/pthread_join.c 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/pthread_join.c 2013-06-25 07:42:37 UTC (rev 4607)
@@ -89,7 +89,7 @@
result = EINVAL;
else
/* Wait for the child. */
- lll_wait_tid (pd->tid);
+ lll_wait_tid (pd->ktid);
/* Restore cancellation mode. */
Modified: trunk/glibc-ports/fbtl/pthread_timedjoin.c
===================================================================
--- trunk/glibc-ports/fbtl/pthread_timedjoin.c 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/pthread_timedjoin.c 2013-06-25 07:42:37 UTC (rev 4607)
@@ -78,7 +78,7 @@
/* Wait for the child. */
- result = lll_timedwait_tid (pd->tid, abstime);
+ result = lll_timedwait_tid (pd->ktid, abstime);
/* Restore cancellation mode. */
Modified: trunk/glibc-ports/fbtl/pthread_tryjoin.c
===================================================================
--- trunk/glibc-ports/fbtl/pthread_tryjoin.c 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/pthread_tryjoin.c 2013-06-25 07:42:37 UTC (rev 4607)
@@ -53,7 +53,7 @@
return EDEADLK;
/* Return right away if the thread hasn't terminated yet. */
- if (pd->tid != 0)
+ if (pd->tid != KTID_TERMINATED)
return EBUSY;
/* Wait for the thread to finish. If it is already locked something
Modified: trunk/glibc-ports/fbtl/sysdeps/pthread/createthread.c
===================================================================
--- trunk/glibc-ports/fbtl/sysdeps/pthread/createthread.c 2013-06-25 07:41:24 UTC (rev 4606)
+++ trunk/glibc-ports/fbtl/sysdeps/pthread/createthread.c 2013-06-25 07:42:37 UTC (rev 4607)
@@ -47,6 +47,22 @@
#endif
+struct rtprio;
+struct thr_param {
+ void (*start_func)(void *); /* thread entry function. */
+ void *arg; /* argument for entry function. */
+ char *stack_base; /* stack base address. */
+ size_t stack_size; /* stack size. */
+ char *tls_base; /* tls base address. */
+ size_t tls_size; /* tls size. */
+ long *child_tid; /* address to store new TID. */
+ long *parent_tid; /* parent accesses the new TID here. */
+ int flags; /* thread flags. */
+ struct rtprio *rtp; /* Real-time scheduling priority */
+ void *spare[3]; /* TODO: cpu affinity mask etc. */
+};
+
+
static int
do_clone (struct pthread *pd, const struct pthread_attr *attr,
int clone_flags, int (*fct) (void *), STACK_VARIABLES_PARMS,
@@ -56,6 +72,8 @@
PREPARE_CREATE;
#endif
+ struct thr_param p;
+
if (__builtin_expect (stopped != 0, 0))
/* We make sure the thread does not run far by forcing it to get a
lock. We lock it here too so that the new thread cannot continue
@@ -71,13 +89,33 @@
is no kosher thing a signal handler interrupting us right here can do
that cares whether the thread count is correct. */
atomic_increment (&__nptl_nthreads);
-
+#if 0
int rc = ARCH_CLONE (fct, STACK_VARIABLES_ARGS, clone_flags,
pd, &pd->tid, TLS_VALUE, &pd->tid);
+#else
+ memset(&p, 0, sizeof(p));
+ p.start_func = fct;
+ p.arg = pd;
+ p.stack_base = pd->stackblock;
+ p.stack_size = STACK_VARIABLES_ARGS - pd->stackblock;
+ p.tls_base = (char*)pd;
+ p.child_tid = &(pd->ktid);
+
+ int rc = INLINE_SYSCALL(thr_new, 2, &p, sizeof(p));
+
+ if (rc)
+ {
+ errno = rc;
+ rc = -1;;
+ }
+#endif
+
+
if (__builtin_expect (rc == -1, 0))
{
atomic_decrement (&__nptl_nthreads); /* Oops, we lied for a second. */
+ pd->ktid = 0;
/* Perhaps a thread wants to change the IDs and if waiting
for this stillborn thread. */
More information about the Glibc-bsd-commits
mailing list