summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2005-12-22 06:55:04 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2005-12-22 06:55:04 +0000
commit14d889fb3cca316e399b08b9c75cd9d73b766c97 (patch)
tree3afeb26bec0f67b2b3a280ad9c63c41e21aaaffc /sys
parenta0e3210399ceb6e15617efea2146d974cfd89535 (diff)
fix memory leak conditions in thrsleep and significantly simplify
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/init_main.c3
-rw-r--r--sys/kern/kern_fork.c3
-rw-r--r--sys/kern/kern_proc.c10
-rw-r--r--sys/kern/kern_synch.c44
-rw-r--r--sys/sys/proc.h9
5 files changed, 21 insertions, 48 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 16798e2c49d..0217b3f7f60 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.126 2005/12/03 18:09:08 tedu Exp $ */
+/* $OpenBSD: init_main.c,v 1.127 2005/12/22 06:55:03 tedu Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -272,7 +272,6 @@ main(void *framep)
p->p_thrparent = p;
LIST_INIT(&p->p_thrchildren);
- LIST_INIT(&p->p_sleepers);
p->p_flag = P_INMEM | P_SYSTEM | P_NOCLDWAIT;
p->p_stat = SONPROC;
diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c
index fd26a81b0c8..7840ea2726c 100644
--- a/sys/kern/kern_fork.c
+++ b/sys/kern/kern_fork.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_fork.c,v 1.80 2005/12/04 21:21:46 tedu Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.81 2005/12/22 06:55:03 tedu Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
@@ -294,7 +294,6 @@ fork1(struct proc *p1, int exitsig, int flags, void *stack, size_t stacksize,
}
LIST_INIT(&p2->p_thrchildren);
- LIST_INIT(&p2->p_sleepers);
#ifdef KTRACE
/*
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index ea7a33bce5c..5a11b8f6202 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_proc.c,v 1.30 2005/12/04 05:49:12 deraadt Exp $ */
+/* $OpenBSD: kern_proc.c,v 1.31 2005/12/22 06:55:03 tedu Exp $ */
/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */
/*
@@ -81,10 +81,6 @@ void pgrpdump(void);
void
procinit(void)
{
-#ifdef RTHREADS
- extern struct pool sleeper_pool;
-#endif
-
LIST_INIT(&allproc);
LIST_INIT(&zombproc);
@@ -107,10 +103,6 @@ procinit(void)
&pool_allocator_nointr);
pool_init(&pcred_pool, sizeof(struct pcred), 0, 0, 0, "pcredpl",
&pool_allocator_nointr);
-#ifdef RTHREADS
- pool_init(&sleeper_pool, sizeof(struct twaitnode), 0, 0, 0, "thrwaitpl",
- &pool_allocator_nointr);
-#endif
}
/*
diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c
index 53ba0df6578..8a51b0c1aec 100644
--- a/sys/kern/kern_synch.c
+++ b/sys/kern/kern_synch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_synch.c,v 1.71 2005/12/14 06:54:38 tedu Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.72 2005/12/22 06:55:03 tedu Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
@@ -378,8 +378,6 @@ sys_sched_yield(struct proc *p, void *v, register_t *retval)
#ifdef RTHREADS
-struct pool sleeper_pool;
-
int
sys_thrsleep(struct proc *p, void *v, register_t *revtal)
{
@@ -388,23 +386,9 @@ sys_thrsleep(struct proc *p, void *v, register_t *revtal)
int timo = SCARG(uap, timeout);
_spinlock_lock_t *lock = SCARG(uap, lock);
_spinlock_lock_t unlocked = _SPINLOCK_UNLOCKED;
-
- struct twaitnode *n, *n2;
int error;
- n = pool_get(&sleeper_pool, PR_WAITOK);
- n->t_ident = ident;
- /* we may have slept */
- LIST_FOREACH(n2, &p->p_thrparent->p_sleepers, t_next) {
- if (n2->t_ident == ident)
- break;
- }
- if (n2) {
- pool_put(&sleeper_pool, n);
- n = n2;
- } else {
- LIST_INSERT_HEAD(&p->p_thrparent->p_sleepers, n, t_next);
- }
+ p->p_thrslpid = ident;
if (lock)
copyout(&unlocked, lock, sizeof(unlocked));
@@ -414,7 +398,7 @@ sys_thrsleep(struct proc *p, void *v, register_t *revtal)
timo = timo / (1000 / hz);
if (timo < 0)
timo = 0;
- error = tsleep(n, PUSER | PCATCH, "thrsleep", timo);
+ error = tsleep(&p->p_thrslpid, PUSER | PCATCH, "thrsleep", timo);
return (error);
@@ -425,19 +409,23 @@ sys_thrwakeup(struct proc *p, void *v, register_t *retval)
{
struct sys_thrwakeup_args *uap = v;
long ident = (long)SCARG(uap, ident);
- struct twaitnode *n;
+ struct proc *q;
+ int found = 0;
- LIST_FOREACH(n, &p->p_thrparent->p_sleepers, t_next) {
- if (n->t_ident == ident) {
- LIST_REMOVE(n, t_next);
- break;
+ /* have to check the parent, it's not in the thread list */
+ if (p->p_thrparent->p_thrslpid == ident) {
+ wakeup(&p->p_thrparent->p_thrslpid);
+ found = 1;
+ }
+ LIST_FOREACH(q, &p->p_thrparent->p_thrchildren, p_thrsib) {
+ if (q->p_thrslpid == ident) {
+ wakeup(&q->p_thrslpid);
+ q->p_thrslpid = 0;
+ found = 1;
}
}
- if (!n)
+ if (!found)
return (ESRCH);
- wakeup(n);
- pool_put(&sleeper_pool, n);
- yield();
return (0);
}
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index df5be44facb..b7280305a99 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.83 2005/12/07 19:04:50 deraadt Exp $ */
+/* $OpenBSD: proc.h,v 1.84 2005/12/22 06:55:03 tedu Exp $ */
/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
/*-
@@ -113,11 +113,6 @@ struct emul {
extern struct emul *emulsw[]; /* All emuls in system */
extern int nemuls; /* Number of emuls */
-struct twaitnode {
- long t_ident;
- LIST_ENTRY(twaitnode) t_next;
-};
-
/*
* Description of a process.
*
@@ -170,7 +165,7 @@ struct proc {
struct proc *p_thrparent;
LIST_ENTRY(proc) p_thrsib;
LIST_HEAD(, proc) p_thrchildren;
- LIST_HEAD(, twaitnode) p_sleepers;
+ long p_thrslpid; /* for thrsleep syscall */
/* scheduling */