From 7f27b397caa5b6b585a186c2351831d2788fa5f9 Mon Sep 17 00:00:00 2001 From: aiju Date: Fri, 29 Jul 2011 16:24:52 +0200 Subject: nusb: more locking, also close dfd --- sys/src/cmd/nusb/usbd/hub.c | 3 +++ sys/src/cmd/nusb/usbd/usbd.c | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/sys/src/cmd/nusb/usbd/hub.c b/sys/src/cmd/nusb/usbd/hub.c index d18760318..6d64c001d 100644 --- a/sys/src/cmd/nusb/usbd/hub.c +++ b/sys/src/cmd/nusb/usbd/hub.c @@ -6,6 +6,7 @@ #include "fns.h" Hub *hubs; +QLock hublock; static int nhubs; static int mustdump; static int pollms = Pollms; @@ -676,6 +677,7 @@ work(void) * have to poll the root hub(s) in any case. */ for(;;){ + qlock(&hublock); Again: for(h = hubs; h != nil; h = h->next) for(i = 1; i <= h->nport; i++) @@ -683,6 +685,7 @@ Again: /* changes in hub list; repeat */ goto Again; } + qunlock(&hublock); sleep(pollms); if(mustdump) dump(); diff --git a/sys/src/cmd/nusb/usbd/usbd.c b/sys/src/cmd/nusb/usbd/usbd.c index 1217bcdf5..79990e233 100644 --- a/sys/src/cmd/nusb/usbd/usbd.c +++ b/sys/src/cmd/nusb/usbd/usbd.c @@ -239,12 +239,16 @@ enumerate(Event **l) static void usbdopen(Req *req) { + extern QLock hublock; + if(req->fid->qid.path == Qusbevent){ + qlock(&hublock); qlock(&evlock); enumerate(&req->fid->aux); ((Event *)req->fid->aux)->ref++; ((Event *)req->fid->aux)->prev--; qunlock(&evlock); + qunlock(&hublock); } respond(req, nil); } @@ -307,6 +311,8 @@ startdev(Port *p) fprint(2, "okay what?\n"); return -1; } + close(d->dfd); + d->dfd = -1; pushevent(formatdev(d)); return 0; } -- cgit v1.2.3