summaryrefslogtreecommitdiff
path: root/sysdeps/l4
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/l4')
-rw-r--r--sysdeps/l4/bits/pthread-np.h44
-rw-r--r--sysdeps/l4/hurd/ia32/pt-machdep.c (renamed from sysdeps/l4/hurd/i386/pt-machdep.c)0
-rw-r--r--sysdeps/l4/hurd/ia32/pt-setup.c (renamed from sysdeps/l4/hurd/i386/pt-setup.c)18
-rw-r--r--sysdeps/l4/hurd/powerpc/pt-machdep.c20
-rw-r--r--sysdeps/l4/hurd/powerpc/pt-setup.c93
-rw-r--r--sysdeps/l4/hurd/pt-kill.c30
-rw-r--r--sysdeps/l4/hurd/pt-sigstate-destroy.c28
-rw-r--r--sysdeps/l4/hurd/pt-sigstate-init.c28
-rw-r--r--sysdeps/l4/hurd/pt-sigstate.c33
-rw-r--r--sysdeps/l4/hurd/pt-sysdep.h16
-rw-r--r--sysdeps/l4/pt-block.c2
-rw-r--r--sysdeps/l4/pt-create-np.c46
-rw-r--r--sysdeps/l4/pt-docancel.c3
-rw-r--r--sysdeps/l4/pt-pool-np.c54
-rw-r--r--sysdeps/l4/pt-spin.c63
-rw-r--r--sysdeps/l4/pt-stack-alloc.c46
-rw-r--r--sysdeps/l4/pt-thread-alloc.c22
-rw-r--r--sysdeps/l4/pt-thread-halt.c31
-rw-r--r--sysdeps/l4/pt-thread-init.c34
-rw-r--r--sysdeps/l4/pt-thread-start.c62
-rw-r--r--sysdeps/l4/pt-timedblock.c34
-rw-r--r--sysdeps/l4/pt-wakeup.c4
22 files changed, 577 insertions, 134 deletions
diff --git a/sysdeps/l4/bits/pthread-np.h b/sysdeps/l4/bits/pthread-np.h
new file mode 100644
index 00000000..3a98cd3f
--- /dev/null
+++ b/sysdeps/l4/bits/pthread-np.h
@@ -0,0 +1,44 @@
+/* Non-portable functions. L4 version.
+ Copyright (C) 2003, 2007 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/*
+ * Never include this file directly; use <pthread.h> or <cthreads.h> instead.
+ */
+
+#ifndef _BITS_PTHREAD_NP_H
+#define _BITS_PTHREAD_NP_H 1
+
+#include <l4.h>
+
+/* Create a thread with attributes given by ATTR, executing
+ START_ROUTINE with argument ARG. TID is the provided L4
+ kernel thread. */
+extern int pthread_create_from_l4_tid_np (pthread_t *thread,
+ const pthread_attr_t *attr,
+ _L4_thread_id_t tid,
+ void *(*start_routine)(void *),
+ void *arg);
+
+/* Add the thread TID to the internal kernel thread pool. */
+extern int pthread_pool_add_np (_L4_thread_id_t tid);
+
+/* Get the first thread from the pool. */
+extern _L4_thread_id_t pthread_pool_get_np (void);
+
+#endif /* bits/pthread-np.h */
diff --git a/sysdeps/l4/hurd/i386/pt-machdep.c b/sysdeps/l4/hurd/ia32/pt-machdep.c
index dbf5cd7e..dbf5cd7e 100644
--- a/sysdeps/l4/hurd/i386/pt-machdep.c
+++ b/sysdeps/l4/hurd/ia32/pt-machdep.c
diff --git a/sysdeps/l4/hurd/i386/pt-setup.c b/sysdeps/l4/hurd/ia32/pt-setup.c
index fe77d533..e244dc16 100644
--- a/sysdeps/l4/hurd/i386/pt-setup.c
+++ b/sysdeps/l4/hurd/ia32/pt-setup.c
@@ -17,7 +17,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <l4/l4.h>
+#include <l4.h>
#include <pt-internal.h>
@@ -39,16 +39,16 @@ static void *
stack_setup (struct __pthread *thread,
void *(*start_routine)(void *), void *arg)
{
- L4_Word_t *top;
+ l4_word_t *top;
/* Calculate top of the new stack. */
- top = (L4_Word_t *) ((L4_Word_t) thread->stackaddr + thread->stacksize);
+ top = (l4_word_t *) ((l4_word_t) thread->stackaddr + thread->stacksize);
if (start_routine)
{
/* Set up call frame. */
- *--top = (L4_Word_t) arg; /* Argument to START_ROUTINE. */
- *--top = (L4_Word_t) start_routine;
+ *--top = (l4_word_t) arg; /* Argument to START_ROUTINE. */
+ *--top = (l4_word_t) start_routine;
*--top = 0; /* Fake return address. */
}
@@ -63,10 +63,10 @@ __pthread_setup (struct __pthread *thread,
thread->mcontext.pc = entry_point;
thread->mcontext.sp = stack_setup (thread, start_routine, arg);
- if (L4_SameThreads (thread->threadid, L4_Myself ()))
- L4_Set_MyUserDefinedHandle (thread);
+ if (l4_same_threads (thread->threadid, l4_myself ()))
+ l4_set_user_defined_handle ((l4_word_t) thread);
else
- L4_Set_UserDefinedHandle (thread->threadid, thread);
-
+ l4_set_user_defined_handle_of (thread->threadid,
+ (l4_word_t) thread);
return 0;
}
diff --git a/sysdeps/l4/hurd/powerpc/pt-machdep.c b/sysdeps/l4/hurd/powerpc/pt-machdep.c
new file mode 100644
index 00000000..754d203e
--- /dev/null
+++ b/sysdeps/l4/hurd/powerpc/pt-machdep.c
@@ -0,0 +1,20 @@
+/* Machine dependent pthreads code. Hurd/PowerPC version.
+ Copyright (C) 2003 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+/* Nothing to do. */
diff --git a/sysdeps/l4/hurd/powerpc/pt-setup.c b/sysdeps/l4/hurd/powerpc/pt-setup.c
new file mode 100644
index 00000000..d3cf4ec3
--- /dev/null
+++ b/sysdeps/l4/hurd/powerpc/pt-setup.c
@@ -0,0 +1,93 @@
+/* Setup thread stack. Hurd/PowerPC version.
+ Copyright (C) 2003 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+
+#include <pt-internal.h>
+
+/* Arguments is passed in registers on the PowerPC. But the
+ exchange registers syscall only allows us to set the PC and the
+ stack pointer so we put the entry point and start function on
+ the stack. */
+struct start_info
+{
+ void (*entry_point) (void *(*)(void *), void *);
+ void *(*start_routine) (void *);
+ void *arg;
+};
+
+void first_entry_1 (void);
+
+/* Stage 1 entry function. The start_info structure is inlined on the
+ stack. Put values into registers and call entry function. */
+asm (" ;\
+first_entry_1: ;\
+ lwz 0, 0(1) ;\
+ lwz 3, 4(1) ;\
+ lwz 4, 8(1) ;\
+ mtctr 0 ;\
+ bctrl ;\
+");
+
+/* Set up the stack for THREAD, such that it appears as if
+ START_ROUTINE and ARG were passed to the new thread's entry-point.
+ Return the stack pointer for the new thread. We also take the
+ opportunity to install THREAD in our utcb. */
+static void *
+stack_setup (struct __pthread *thread,
+ void (*entry_point)(void *(*)(void *), void *),
+ void *(*start_routine)(void *), void *arg)
+{
+ l4_word_t *top;
+
+ /* Calculate top of the new stack. */
+ top = (l4_word_t *) ((l4_word_t) thread->stackaddr + thread->stacksize);
+
+ /* Initial stack frame. */
+ top[-4] = 0;
+ top = top - 4;
+
+ if (start_routine)
+ {
+ struct start_info *info = ((struct start_info *) top) - 1;
+
+ info->entry_point = entry_point;
+ info->start_routine = start_routine;
+ info->arg = arg;
+ return (void *) info;
+ }
+ return top;
+}
+
+int
+__pthread_setup (struct __pthread *thread,
+ void (*entry_point)(void *(*)(void *), void *),
+ void *(*start_routine)(void *), void *arg)
+{
+ thread->mcontext.pc = first_entry_1;
+ thread->mcontext.sp = stack_setup (thread, entry_point,
+ start_routine, arg);
+
+ if (l4_same_threads (thread->threadid, l4_myself ()))
+ l4_set_user_defined_handle ((l4_word_t) thread);
+ else
+ l4_set_user_defined_handle_of (thread->threadid,
+ (l4_word_t) thread);
+ return 0;
+}
diff --git a/sysdeps/l4/hurd/pt-kill.c b/sysdeps/l4/hurd/pt-kill.c
new file mode 100644
index 00000000..1e64af49
--- /dev/null
+++ b/sysdeps/l4/hurd/pt-kill.c
@@ -0,0 +1,30 @@
+/* pthread_kill. Hurd version.
+ Copyright (C) 2002 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+
+#include <pt-internal.h>
+
+int
+pthread_kill (pthread_t thread, int sig)
+{
+ return ESRCH;
+}
diff --git a/sysdeps/l4/hurd/pt-sigstate-destroy.c b/sysdeps/l4/hurd/pt-sigstate-destroy.c
new file mode 100644
index 00000000..997a0369
--- /dev/null
+++ b/sysdeps/l4/hurd/pt-sigstate-destroy.c
@@ -0,0 +1,28 @@
+/* Destroy the signal state. Hurd on L4 version.
+ Copyright (C) 2002 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+void
+__pthread_sigstate_destroy (struct __pthread *thread)
+{
+ /* Nothing to do. */
+}
diff --git a/sysdeps/l4/hurd/pt-sigstate-init.c b/sysdeps/l4/hurd/pt-sigstate-init.c
new file mode 100644
index 00000000..25a3920c
--- /dev/null
+++ b/sysdeps/l4/hurd/pt-sigstate-init.c
@@ -0,0 +1,28 @@
+/* Initialize the signal state. Hurd on L4 version.
+ Copyright (C) 2003 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_sigstate_init (struct __pthread *thread)
+{
+ return 0;
+}
diff --git a/sysdeps/l4/hurd/pt-sigstate.c b/sysdeps/l4/hurd/pt-sigstate.c
new file mode 100644
index 00000000..8ab80347
--- /dev/null
+++ b/sysdeps/l4/hurd/pt-sigstate.c
@@ -0,0 +1,33 @@
+/* Set a thread's signal state. Hurd on L4 version.
+ Copyright (C) 2002, 2005 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pthread.h>
+#include <assert.h>
+#include <signal.h>
+
+#include <pt-internal.h>
+
+error_t
+__pthread_sigstate (struct __pthread *thread, int how,
+ const sigset_t *set, sigset_t *oset,
+ int clear_pending)
+{
+ /* FIXME: Do the right thing here. */
+ return 0;
+}
diff --git a/sysdeps/l4/hurd/pt-sysdep.h b/sysdeps/l4/hurd/pt-sysdep.h
index 87175330..0b5abb74 100644
--- a/sysdeps/l4/hurd/pt-sysdep.h
+++ b/sysdeps/l4/hurd/pt-sysdep.h
@@ -1,5 +1,5 @@
/* Internal defenitions for pthreads library.
- Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2002, 2005 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
@@ -20,30 +20,28 @@
#ifndef _PT_SYSDEP_H
#define _PT_SYSDEP_H 1
-#include <l4/l4.h>
-#include <task_client.h>
-#include <machine/vmparam.h>
+#include <l4.h>
/* XXX */
#define _POSIX_THREAD_THREADS_MAX 64
/* The default stack size. */
-#define PTHREAD_STACK_DEFAULT (PAGE_SIZE)
+#define PTHREAD_STACK_DEFAULT 4096
#define PTHREAD_SYSDEP_MEMBERS \
- L4_ThreadId_t threadid; \
- L4_Word_t my_errno;
+ l4_thread_id_t threadid; \
+ l4_word_t my_errno;
extern inline struct __pthread *
__attribute__((__always_inline__))
_pthread_self (void)
{
- return (struct __pthread *) L4_MyUserDefinedHandle ();
+ return (struct __pthread *) l4_user_defined_handle ();
}
extern inline void
-__pthread_stack_dealloc (void *stackaddr, size_t stacksize)
__attribute__((__always_inline__))
+__pthread_stack_dealloc (void *stackaddr, size_t stacksize)
{
/* XXX: can only implement this once we have a working memory manager. */
return;
diff --git a/sysdeps/l4/pt-block.c b/sysdeps/l4/pt-block.c
index 050c6947..933cc285 100644
--- a/sysdeps/l4/pt-block.c
+++ b/sysdeps/l4/pt-block.c
@@ -17,7 +17,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <l4/l4.h>
+#include <l4.h>
#include <pt-internal.h>
diff --git a/sysdeps/l4/pt-create-np.c b/sysdeps/l4/pt-create-np.c
new file mode 100644
index 00000000..68b8b004
--- /dev/null
+++ b/sysdeps/l4/pt-create-np.c
@@ -0,0 +1,46 @@
+/* Thread creation from provided L4 thread.
+ Copyright (C) 2003, 2007 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+
+#include <pt-internal.h>
+
+/* Create a thread with attributes given by ATTR, executing
+ START_ROUTINE with argument ARG. TID is the provided L4
+ kernel thread. */
+int
+pthread_create_from_l4_tid_np (pthread_t *thread,
+ const pthread_attr_t *attr,
+ _L4_thread_id_t tid,
+ void *(*start_routine)(void *), void *arg)
+{
+ int err;
+ struct __pthread *pthread;
+
+#warning Does not use TID.
+ err = __pthread_create_internal (&pthread, attr,
+ start_routine, arg);
+ if (! err)
+ *thread = pthread->thread;
+
+ return err;
+}
diff --git a/sysdeps/l4/pt-docancel.c b/sysdeps/l4/pt-docancel.c
index 9a3bb26c..e832e26e 100644
--- a/sysdeps/l4/pt-docancel.c
+++ b/sysdeps/l4/pt-docancel.c
@@ -30,6 +30,7 @@ call_exit (void)
int
__pthread_do_cancel (struct __pthread *p)
{
+#if 0
assert (p->cancel_pending = 1);
assert (p->cancel_state == PTHREAD_CANCEL_ENABLE);
@@ -46,6 +47,6 @@ __pthread_do_cancel (struct __pthread *p)
&dummy, &dummy, &dummy, &dummy, &dummy,
&dummy_id);
}
-
+#endif
return 0;
}
diff --git a/sysdeps/l4/pt-pool-np.c b/sysdeps/l4/pt-pool-np.c
new file mode 100644
index 00000000..f59a3e2b
--- /dev/null
+++ b/sysdeps/l4/pt-pool-np.c
@@ -0,0 +1,54 @@
+/* Thread pool for L4 threads.
+ Copyright (C) 2004, 2007 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <pt-internal.h>
+#include <l4/thread.h>
+
+static pthread_mutex_t pool_lock = PTHREAD_MUTEX_INITIALIZER;
+
+_L4_thread_id_t pool_list = l4_nilthread;
+
+/* Add the thread TID to the pthread kernel thread pool. */
+int
+pthread_pool_add_np (_L4_thread_id_t tid, bool stop)
+{
+ __pthread_mutex_lock (&pool_lock);
+ /* FIXME: Do error checking. */
+ l4_set_user_defined_handle_of (tid, pool_list);
+ pool_list = tid;
+ __pthread_mutex_unlock (&pool_lock);
+
+ return 0;
+}
+
+
+/* Get the first thread from the pool. */
+_L4_thread_id_t
+pthread_pool_get_np (void)
+{
+ _L4_thread_id_t tid;
+
+ __pthread_mutex_lock (&pool_lock);
+ /* FIXME: Do error checking. */
+ tid = pool_list;
+ if (tid != l4_nilthread)
+ pool_list = l4_user_defined_handle_of (tid);
+ __pthread_mutex_unlock (&pool_lock);
+ return tid;
+}
diff --git a/sysdeps/l4/pt-spin.c b/sysdeps/l4/pt-spin.c
new file mode 100644
index 00000000..b6978b0c
--- /dev/null
+++ b/sysdeps/l4/pt-spin.c
@@ -0,0 +1,63 @@
+/* Spin locks. L4 version.
+ Copyright (C) 2000, 2004 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <l4.h>
+
+#include <pthread.h>
+#include <sched.h>
+
+/* The default for single processor machines; don't spin, it's
+ pointless. */
+#ifndef __PTHREAD_SPIN_COUNT
+# define __PTHREAD_SPIN_COUNT 1
+#endif
+
+/* The number of times to spin while trying to lock a spin lock object
+ before yielding the processor. */
+int __pthread_spin_count = __PTHREAD_SPIN_COUNT;
+
+
+/* Lock the spin lock object LOCK. If the lock is held by another
+ thread spin until it becomes available. */
+int
+_pthread_spin_lock (__pthread_spinlock_t *lock)
+{
+ l4_time_t timeout;
+ int i;
+
+ /* Start with a small timeout of 2 microseconds, then back off
+ exponentially. */
+ timeout = l4_time_period (2);
+
+ while (1)
+ {
+ for (i = 0; i < __pthread_spin_count; i++)
+ {
+ if (__pthread_spin_trylock (lock) == 0)
+ return 0;
+ }
+ l4_sleep (timeout);
+
+ timeout = l4_time_mul2 (timeout);
+ if (timeout == L4_NEVER)
+ timeout = L4_TIME_PERIOD_MAX;
+ }
+}
+
+weak_alias (_pthread_spin_lock, pthread_spin_lock);
diff --git a/sysdeps/l4/pt-stack-alloc.c b/sysdeps/l4/pt-stack-alloc.c
index e28d5310..2ede58fd 100644
--- a/sysdeps/l4/pt-stack-alloc.c
+++ b/sysdeps/l4/pt-stack-alloc.c
@@ -1,5 +1,5 @@
/* Allocate a new stack. L4 Hurd version.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2007 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
@@ -17,41 +17,14 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <l4/l4.h>
+#include <l4.h>
#include <errno.h>
#include <pt-internal.h>
-#define __pthread_stacksize __pthread_default_attr.stacksize
+#include <sys/mman.h>
-#include <l4/sigma0.h>
-#include <hurd/debug.h>
-
-static void *
-allocate_page (void)
-{
- L4_Fpage_t p;
- /* The Kernel Interface page. */
- static L4_KernelInterfacePage_t *kip;
-
- if (! kip)
- kip = L4_GetKernelInterface ();
-
-#define sigma0_tid() (L4_GlobalId (kip->ThreadInfo.X.UserBase, 1))
- p = L4_Sigma0_GetPage (sigma0_tid (),
- L4_Fpage_Set_Attrs (L4_FpageLog2 (-1UL << 10,
- PAGE_SHIFT),
- L4_FullyAccessible));
- p.raw &= ~0x3ff;
-
- printf ("%s: Allocated page %x\n",
- __FUNCTION__, p.raw);
-
- return (void *) p.raw;
-}
-
-
-/* Allocate a new stack of size STACKSIZE. If successfull, store the
+/* Allocate a new stack of size STACKSIZE. If successful, store the
address of the newly allocated stack in *STACKADDR and return 0.
Otherwise return an error code (EINVAL for an invalid stack size,
EAGAIN if the system lacked the necessary resources to allocate a
@@ -59,12 +32,11 @@ allocate_page (void)
int
__pthread_stack_alloc (void **stackaddr, size_t stacksize)
{
- if (stacksize != __pthread_stacksize)
- return EINVAL;
-
- *stackaddr = allocate_page ();
- if (! *stackaddr)
+ void *buffer = mmap (0, stacksize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (buffer == MAP_FAILED)
return EAGAIN;
-
+
+ *stackaddr = buffer;
return 0;
}
diff --git a/sysdeps/l4/pt-thread-alloc.c b/sysdeps/l4/pt-thread-alloc.c
index a9d5e212..fc2f43b4 100644
--- a/sysdeps/l4/pt-thread-alloc.c
+++ b/sysdeps/l4/pt-thread-alloc.c
@@ -1,5 +1,5 @@
-/* Start thread. L4 version.
- Copyright (C) 2002 Free Software Foundation, Inc.
+/* Allocate kernel thread. L4 version.
+ Copyright (C) 2003, 2005 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
@@ -23,20 +23,30 @@
#include <pt-internal.h>
-/* Start THREAD. Get the kernel thread scheduled and running. */
int
-__pthread_thread_start (struct __pthread *thread)
+__pthread_thread_alloc (struct __pthread *thread)
{
error_t err;
/* The main thread is already running of course. */
if (__pthread_num_threads == 1)
{
+ /* XXX: The initialization code needs to make this consistent.
+ Right now, we have none and this whole library is a hack
+ anyways. */
+#warning __pthread_total is inconsistent.
+#if 0
assert (__pthread_total == 1);
- thread->thread_id = L4_Myself ();
+#endif
+ thread->threadid = l4_myself ();
}
else
{
+ thread->threadid = pthread_pool_get_np ();
+ if (thread->threadid != l4_nilthread)
+ return 0;
+
+#if 0
CORBA_Environment env;
env = idl4_default_environment;
@@ -45,8 +55,8 @@ __pthread_thread_start (struct __pthread *thread)
* (L4_Word_t *) &__system_pager,
(L4_Word_t *) &thread->threadid, &env);
if (err)
+#endif
return EAGAIN;
}
-
return 0;
}
diff --git a/sysdeps/l4/pt-thread-halt.c b/sysdeps/l4/pt-thread-halt.c
index 04d622f4..aa2bf43d 100644
--- a/sysdeps/l4/pt-thread-halt.c
+++ b/sysdeps/l4/pt-thread-halt.c
@@ -1,5 +1,5 @@
-/* Deallocate the kernel thread resources. Mach version.
- Copyright (C) 2000,02 Free Software Foundation, Inc.
+/* Deallocate the kernel thread resources. L4version.
+ Copyright (C) 2000, 2002, 2004 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
@@ -19,20 +19,27 @@
#include <assert.h>
#include <errno.h>
-#include <mach.h>
#include <pt-internal.h>
-extern L4_ThreadId_t __task_server;
-
/* Deallocate the kernel thread resources associated with THREAD. */
void
-__pthread_thread_halt (struct __pthread *thread)
+__pthread_thread_halt (struct __pthread *thread, int need_dealloc)
{
- CORBA_Environment env = idl4_default_environment;
- L4_Word_t *t = (L4_Word_t *) &thread->threadid;
-
- assert (*t);
- assert (thread_terminate (__task_server, *t, &env));
- *t = 0;
+ l4_thread_id_t tid = thread->threadid;
+
+ if (need_dealloc)
+ __pthread_dealloc (thread);
+
+ /* There is potential race here: once if TID is the current thread,
+ then once we add TID to the pool, someone can reallocate it
+ before we call stop. However, to start the thread, the caller
+ atomically starts and sets the sp and ip, thus, if the stop has
+ not yet executed at that point, it won't. */
+
+ if (tid != l4_myself ())
+ l4_stop (tid);
+ pthread_pool_add_np (tid);
+ if (tid == l4_myself ())
+ l4_stop (tid);
}
diff --git a/sysdeps/l4/pt-thread-init.c b/sysdeps/l4/pt-thread-init.c
new file mode 100644
index 00000000..ac50d58d
--- /dev/null
+++ b/sysdeps/l4/pt-thread-init.c
@@ -0,0 +1,34 @@
+/* Start thread. L4 version.
+ Copyright (C) 2003 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <pt-internal.h>
+
+/* Initialize provided kernel thread. */
+int
+__pthread_init_provided_thread (struct __pthread *thread,
+ void *p)
+{
+ l4_thread_id_t *tid = (l4_thread_id_t *) p;
+ thread->threadid = *tid;
+ return 0;
+}
diff --git a/sysdeps/l4/pt-thread-start.c b/sysdeps/l4/pt-thread-start.c
index c428d290..10996e1c 100644
--- a/sysdeps/l4/pt-thread-start.c
+++ b/sysdeps/l4/pt-thread-start.c
@@ -1,5 +1,5 @@
/* Start thread. L4 version.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 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
@@ -23,70 +23,18 @@
#include <pt-internal.h>
-#include "task_client.h"
-
-extern L4_ThreadId_t __system_pager;
-extern L4_ThreadId_t __task_server;
-
-#ifndef WORKING_EXREGS
-static void
-send_startup_ipc (L4_ThreadId_t id, L4_Word_t ip, L4_Word_t sp)
-{
- L4_Msg_t msg;
-
- printf ("%s: Sending startup message to %x, "
- "(ip=%x, sp=%x)\n",
- __FUNCTION__, * (L4_Word_t *) &id, ip, sp);
-
- L4_Clear (&msg);
-#ifdef HAVE_PROPAGATION
- L4_Set_VirtualSender (pager_tid);
- L4_Set_Propagation (&msg.tag);
-#endif
- L4_Append_Word (&msg, ip);
- L4_Append_Word (&msg, sp);
-#ifndef HAVE_PROPAGATION
- L4_Append_Word (&msg, *(L4_Word_t *) &id);
- id = __system_pager;
-#if 0
- DODEBUG (2, printf ("%s: Redirecting start request to pager (%x).\n",
- __FUNCTION__, * (L4_Word_t *) &id));
-#endif
-#endif
- L4_LoadMsg (&msg);
- L4_Send (id);
-}
-#endif
-
/* Start THREAD. Get the kernel thread scheduled and running. */
int
__pthread_thread_start (struct __pthread *thread)
{
- error_t err;
-
/* The main thread is already running of course. */
if (__pthread_num_threads == 1)
- {
- assert (__pthread_total == 1);
- assert (thread->thread_id == L4_Myself ());
- }
+ assert (__pthread_total == 1);
else
{
- env = idl4_default_environment;
- err = thread_resume (__task_server,
- * (L4_Word_t *) &thread->threadid,
- &env);
- assert (! err);
-
-#ifndef WORKING_EXREGS
- L4_AbortIpc_and_stop (thread->threadid);
- L4_Start_SpIp (thread->threadid, (L4_Word_t) thread->mcontext.sp,
- (L4_Word_t) thread->mcontext.pc);
-#endif
- send_startup_ipc (thread->threadid, (L4_Word_t) thread->mcontext.pc,
- (L4_Word_t) thread->mcontext.sp);
-
+ l4_set_pager_of (thread->threadid, l4_pager ());
+ l4_start_sp_ip (thread->threadid, (l4_word_t) thread->mcontext.sp,
+ (l4_word_t) thread->mcontext.pc);
}
-
return 0;
}
diff --git a/sysdeps/l4/pt-timedblock.c b/sysdeps/l4/pt-timedblock.c
new file mode 100644
index 00000000..fda14401
--- /dev/null
+++ b/sysdeps/l4/pt-timedblock.c
@@ -0,0 +1,34 @@
+/* Block a thread with a timeout. L4 version.
+ Copyright (C) 2000,02 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 Library General Public License as
+ published by the Free Software Foundation; either version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <assert.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+
+#include <pt-internal.h>
+
+/* Block THREAD. */
+error_t
+__pthread_timedblock (struct __pthread *thread,
+ const struct timespec *abstime)
+{
+ __pthread_block (thread);
+ return 0;
+}
diff --git a/sysdeps/l4/pt-wakeup.c b/sysdeps/l4/pt-wakeup.c
index 7b00e4f6..342a2204 100644
--- a/sysdeps/l4/pt-wakeup.c
+++ b/sysdeps/l4/pt-wakeup.c
@@ -17,7 +17,7 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
-#include <l4/l4.h>
+#include <l4.h>
#include <pt-internal.h>
@@ -25,5 +25,5 @@
void
__pthread_wakeup (struct __pthread *thread)
{
- L4_Send (thread->threadid);
+ l4_send (thread->threadid);
}