Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat/mach - Rework the Mach semaphore code to handle t...
details: https://anonhg.NetBSD.org/src/rev/5cfc71530f3c
branches: trunk
changeset: 556904:5cfc71530f3c
user: manu <manu%NetBSD.org@localhost>
date: Tue Dec 30 00:15:46 2003 +0000
description:
- Rework the Mach semaphore code to handle threads instead of processes
- Add 2 system calls: semaphore_signal_thread and sempaphore_signal_all (the
latter being untested)
- semaphore_signal_thread arguments list was wrong
diffstat:
sys/compat/mach/mach_exec.c | 8 +-
sys/compat/mach/mach_misc.c | 28 +----
sys/compat/mach/mach_port.c | 5 +-
sys/compat/mach/mach_semaphore.c | 200 +++++++++++++++++++++++++++++-------
sys/compat/mach/mach_semaphore.h | 12 +-
sys/compat/mach/mach_syscall.h | 4 +-
sys/compat/mach/mach_syscallargs.h | 3 +-
sys/compat/mach/mach_syscalls.c | 4 +-
sys/compat/mach/mach_sysent.c | 6 +-
sys/compat/mach/syscalls.master | 5 +-
10 files changed, 186 insertions(+), 89 deletions(-)
diffs (truncated from 577 to 300 lines):
diff -r d83ec937e39e -r 5cfc71530f3c sys/compat/mach/mach_exec.c
--- a/sys/compat/mach/mach_exec.c Tue Dec 30 00:14:20 2003 +0000
+++ b/sys/compat/mach/mach_exec.c Tue Dec 30 00:15:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_exec.c,v 1.50 2003/12/28 13:28:39 manu Exp $ */
+/* $NetBSD: mach_exec.c,v 1.51 2003/12/30 00:15:46 manu Exp $ */
/*-
* Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.50 2003/12/28 13:28:39 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.51 2003/12/30 00:15:46 manu Exp $");
#include "opt_syscall_debug.h"
@@ -369,8 +369,6 @@
mach_e_lwp_exit(proc_representative_lwp(p));
- mach_semaphore_cleanup(p);
-
med = (struct mach_emuldata *)p->p_emuldata;
lockmgr(&med->med_rightlock, LK_EXCLUSIVE, NULL);
@@ -450,6 +448,8 @@
{
struct mach_lwp_emuldata *mle;
+ mach_semaphore_cleanup(l);
+
#ifdef DIAGNOSTIC
if (l->l_emuldata == NULL) {
printf("lwp_emuldata already freed\n");
diff -r d83ec937e39e -r 5cfc71530f3c sys/compat/mach/mach_misc.c
--- a/sys/compat/mach/mach_misc.c Tue Dec 30 00:14:20 2003 +0000
+++ b/sys/compat/mach/mach_misc.c Tue Dec 30 00:15:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_misc.c,v 1.20 2003/12/28 23:00:36 manu Exp $ */
+/* $NetBSD: mach_misc.c,v 1.21 2003/12/30 00:15:46 manu Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_misc.c,v 1.20 2003/12/28 23:00:36 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_misc.c,v 1.21 2003/12/30 00:15:46 manu Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -88,30 +88,6 @@
int
-mach_sys_semaphore_signal_all_trap(struct lwp *l, void *v, register_t *r) {
-#ifdef DEBUG_MACH
- struct mach_sys_semaphore_signal_all_trap_args *ap = v;
-#endif
- *r = 0;
- DPRINTF(("mach_sys_semaphore_signal_all_trap(0x%x);\n",
- SCARG(ap, signal_name)));
- return 0;
-}
-
-
-int
-mach_sys_semaphore_signal_thread_trap(struct lwp *l, void *v, register_t *r) {
-#ifdef DEBUG_MACH
- struct mach_sys_semaphore_signal_thread_trap_args *ap = v;
-#endif
- *r = 0;
- DPRINTF(("mach_sys_semaphore_signal_thread_trap(0x%x);\n",
- SCARG(ap, signal_name)));
- return 0;
-}
-
-
-int
mach_sys_semaphore_timedwait_trap(struct lwp *l, void *v, register_t *r) {
#ifdef DEBUG_MACH
struct mach_sys_semaphore_timedwait_trap_args *ap = v;
diff -r d83ec937e39e -r 5cfc71530f3c sys/compat/mach/mach_port.c
--- a/sys/compat/mach/mach_port.c Tue Dec 30 00:14:20 2003 +0000
+++ b/sys/compat/mach/mach_port.c Tue Dec 30 00:15:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_port.c,v 1.49 2003/12/21 07:53:59 simonb Exp $ */
+/* $NetBSD: mach_port.c,v 1.50 2003/12/30 00:15:46 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include "opt_compat_darwin.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.49 2003/12/21 07:53:59 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.50 2003/12/30 00:15:46 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -632,6 +632,7 @@
{
struct mach_message *mm;
+ printf("port_put: %p\n", mp);
if (mp->mp_refcount > 0) {
uprintf("mach_port_put: trying to free a referenced port\n");
return;
diff -r d83ec937e39e -r 5cfc71530f3c sys/compat/mach/mach_semaphore.c
--- a/sys/compat/mach/mach_semaphore.c Tue Dec 30 00:14:20 2003 +0000
+++ b/sys/compat/mach/mach_semaphore.c Tue Dec 30 00:15:46 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_semaphore.c,v 1.9 2003/12/28 23:00:36 manu Exp $ */
+/* $NetBSD: mach_semaphore.c,v 1.10 2003/12/30 00:15:46 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_semaphore.c,v 1.9 2003/12/28 23:00:36 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_semaphore.c,v 1.10 2003/12/30 00:15:46 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -61,15 +61,15 @@
static LIST_HEAD(mach_semaphore_list, mach_semaphore) mach_semaphore_list;
static struct lock mach_semaphore_list_lock;
static struct pool mach_semaphore_list_pool;
-static struct pool mach_waiting_proc_pool;
+static struct pool mach_waiting_lwp_pool;
/* Function to manipulate them */
static struct mach_semaphore *mach_semaphore_get(int, int);
static void mach_semaphore_put(struct mach_semaphore *);
-static struct mach_waiting_proc *mach_waiting_proc_get
- (struct proc *, struct mach_semaphore *);
-static void mach_waiting_proc_put
- (struct mach_waiting_proc *, struct mach_semaphore *, int);
+static struct mach_waiting_lwp *mach_waiting_lwp_get
+ (struct lwp *, struct mach_semaphore *);
+static void mach_waiting_lwp_put
+ (struct mach_waiting_lwp *, struct mach_semaphore *, int);
int
mach_sys_semaphore_wait_trap(l, v, retval)
@@ -81,7 +81,7 @@
syscallarg(mach_port_name_t) wait_name;
} */ *uap = v;
struct mach_semaphore *ms;
- struct mach_waiting_proc *mwp;
+ struct mach_waiting_lwp *mwl;
struct mach_right *mr;
mach_port_t mn;
int blocked = 0;
@@ -102,10 +102,10 @@
lockmgr(&ms->ms_lock, LK_RELEASE, NULL);
if (blocked != 0) {
- mwp = mach_waiting_proc_get(l->l_proc, ms);
+ mwl = mach_waiting_lwp_get(l, ms);
while (ms->ms_value < 0)
- tsleep(mwp, PZERO|PCATCH, "sem_wait", 0);
- mach_waiting_proc_put(mwp, ms, 0);
+ tsleep(mwl, PZERO|PCATCH, "sem_wait", 0);
+ mach_waiting_lwp_put(mwl, ms, 0);
}
return 0;
}
@@ -120,7 +120,7 @@
syscallarg(mach_port_name_t) signal_name;
} */ *uap = v;
struct mach_semaphore *ms;
- struct mach_waiting_proc *mwp;
+ struct mach_waiting_lwp *mwl;
struct mach_right *mr;
mach_port_t mn;
int unblocked = 0;
@@ -132,7 +132,7 @@
if (mr->mr_port->mp_datatype != MACH_MP_SEMAPHORE)
return EINVAL;
- ms = (struct mach_semaphore *)mr->mr_port->mp_datatype;
+ ms = (struct mach_semaphore *)mr->mr_port->mp_data;
lockmgr(&ms->ms_lock, LK_EXCLUSIVE, NULL);
ms->ms_value++;
@@ -142,8 +142,8 @@
if (unblocked != 0) {
lockmgr(&ms->ms_lock, LK_SHARED, NULL);
- mwp = TAILQ_FIRST(&ms->ms_waiting);
- wakeup(mwp);
+ mwl = TAILQ_FIRST(&ms->ms_waiting);
+ wakeup(mwl);
lockmgr(&ms->ms_lock, LK_RELEASE, NULL);
}
return 0;
@@ -217,7 +217,7 @@
lockinit(&mach_semaphore_list_lock, PZERO|PCATCH, "mach_sem", 0, 0);
pool_init(&mach_semaphore_list_pool, sizeof (struct mach_semaphore),
0, 0, 0, "mach_sem_pool", NULL);
- pool_init(&mach_waiting_proc_pool, sizeof (struct mach_waiting_proc),
+ pool_init(&mach_waiting_lwp_pool, sizeof (struct mach_waiting_lwp),
0, 0, 0, "mach_waitp_pool", NULL);
return;
@@ -248,11 +248,11 @@
mach_semaphore_put(ms)
struct mach_semaphore *ms;
{
- struct mach_waiting_proc *mwp;
+ struct mach_waiting_lwp *mwl;
lockmgr(&ms->ms_lock, LK_EXCLUSIVE, NULL);
- while ((mwp = TAILQ_FIRST(&ms->ms_waiting)) != NULL)
- mach_waiting_proc_put(mwp, ms, 0);
+ while ((mwl = TAILQ_FIRST(&ms->ms_waiting)) != NULL)
+ mach_waiting_lwp_put(mwl, ms, 0);
lockmgr(&ms->ms_lock, LK_RELEASE, NULL);
lockmgr(&ms->ms_lock, LK_DRAIN, NULL);
@@ -265,36 +265,36 @@
return;
}
-static struct mach_waiting_proc *
-mach_waiting_proc_get(p, ms)
- struct proc *p;
+static struct mach_waiting_lwp *
+mach_waiting_lwp_get(l, ms)
+ struct lwp *l;
struct mach_semaphore *ms;
{
- struct mach_waiting_proc *mwp;
+ struct mach_waiting_lwp *mwl;
- mwp = (struct mach_waiting_proc *)pool_get(&mach_waiting_proc_pool,
+ mwl = (struct mach_waiting_lwp *)pool_get(&mach_waiting_lwp_pool,
M_WAITOK);
- mwp->mwp_p = p;
+ mwl->mwl_l = l;
lockmgr(&ms->ms_lock, LK_EXCLUSIVE, NULL);
- TAILQ_INSERT_TAIL(&ms->ms_waiting, mwp, mwp_list);
+ TAILQ_INSERT_TAIL(&ms->ms_waiting, mwl, mwl_list);
lockmgr(&ms->ms_lock, LK_RELEASE, NULL);
- return mwp;
+ return mwl;
}
static void
-mach_waiting_proc_put(mwp, ms, locked)
- struct mach_waiting_proc *mwp;
+mach_waiting_lwp_put(mwl, ms, locked)
+ struct mach_waiting_lwp *mwl;
struct mach_semaphore *ms;
int locked;
{
if (!locked)
lockmgr(&ms->ms_lock, LK_EXCLUSIVE, NULL);
- TAILQ_REMOVE(&ms->ms_waiting, mwp, mwp_list);
+ TAILQ_REMOVE(&ms->ms_waiting, mwl, mwl_list);
if (!locked)
lockmgr(&ms->ms_lock, LK_RELEASE, NULL);
- pool_put(&mach_waiting_proc_pool, mwp);
+ pool_put(&mach_waiting_lwp_pool, mwl);
return;
}
@@ -304,19 +304,19 @@
* can be some memory leaks here.
*/
void
-mach_semaphore_cleanup(p)
- struct proc *p;
+mach_semaphore_cleanup(l)
+ struct lwp *l;
{
struct mach_semaphore *ms;
- struct mach_waiting_proc *mwp;
+ struct mach_waiting_lwp *mwl;
lockmgr(&mach_semaphore_list_lock, LK_SHARED, NULL);
LIST_FOREACH(ms, &mach_semaphore_list, ms_list) {
lockmgr(&ms->ms_lock, LK_SHARED, NULL);
- TAILQ_FOREACH(mwp, &ms->ms_waiting, mwp_list)
- if (mwp->mwp_p == p) {
+ TAILQ_FOREACH(mwl, &ms->ms_waiting, mwl_list)
+ if (mwl->mwl_l == l) {
lockmgr(&ms->ms_lock, LK_UPGRADE, NULL);
- mach_waiting_proc_put(mwp, ms, 0);
+ mach_waiting_lwp_put(mwl, ms, 0);
ms->ms_value++;
if (ms->ms_value >= 0)
Home |
Main Index |
Thread Index |
Old Index