From f843c385b1c577e349de9ec9a4a256aad48b1bcf Mon Sep 17 00:00:00 2001 From: John Baldwin Date: Tue, 23 Jan 2001 21:06:30 +0000 Subject: [PATCH] - Add necessary proc locking. - Use proper atomic operations to make the run time initialization controlled by svr_str_initialized be MP safe. - Use appropriate queue(3) macros where needed. --- sys/dev/streams/streams.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/sys/dev/streams/streams.c b/sys/dev/streams/streams.c index b7da7eef762..1d779f4a9f3 100644 --- a/sys/dev/streams/streams.c +++ b/sys/dev/streams/streams.c @@ -207,8 +207,12 @@ streamsopen(dev_t dev, int oflags, int devtype, struct proc *p) int error; int family; - if (p->p_dupfd >= 0) + PROC_LOCK(p); + if (p->p_dupfd >= 0) { + PROC_UNLOCK(p); return ENODEV; + } + PROC_UNLOCK(p); switch (minor(dev)) { case dev_udp: @@ -271,7 +275,9 @@ streamsopen(dev_t dev, int oflags, int devtype, struct proc *p) fp->f_type = DTYPE_SOCKET; (void)svr4_stream_get(fp); + PROC_LOCK(p); p->p_dupfd = fd; + PROC_UNLOCK(p); return ENXIO; } @@ -318,7 +324,9 @@ svr4_ptm_alloc(p) case ENXIO: return error; case 0: + PROC_LOCK(p); p->p_dupfd = p->p_retval[0]; + PROC_UNLOCK(p); return ENXIO; default: if (ttynumbers[++n] == '\0') { @@ -367,13 +375,15 @@ svr4_delete_socket(p, fp) struct svr4_sockcache_entry *e; void *cookie = ((struct socket *) fp->f_data)->so_emuldata; - if (!svr4_str_initialized) { - TAILQ_INIT(&svr4_head); - svr4_str_initialized = 1; + while (svr4_str_initialized != 2) { + if (atomic_cmpset_acq_int(&svr4_str_initialized, 0, 1)) { + TAILQ_INIT(&svr4_head); + atomic_store_rel_int(&svr4_str_initialized, 2); + } return; } - for (e = svr4_head.tqh_first; e != NULL; e = e->entries.tqe_next) + TAILQ_FOREACH(e, &svr4_head, entries) if (e->p == p && e->cookie == cookie) { TAILQ_REMOVE(&svr4_head, e, entries); DPRINTF(("svr4_delete_socket: %s [%p,%d,%d]\n",