ref: 7f27b397caa5b6b585a186c2351831d2788fa5f9
parent: 61d322679b65aedb569af6f4e90764c106eca9ef
author: aiju <[email protected]>
date: Fri Jul 29 12:24:52 EDT 2011
nusb: more locking, also close dfd
--- 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 @@
* 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 @@
/* changes in hub list; repeat */
goto Again;
}
+ qunlock(&hublock);
sleep(pollms);
if(mustdump)
dump();
--- a/sys/src/cmd/nusb/usbd/usbd.c
+++ b/sys/src/cmd/nusb/usbd/usbd.c
@@ -239,12 +239,16 @@
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 @@
fprint(2, "okay what?\n");
return -1;
}
+ close(d->dfd);
+ d->dfd = -1;
pushevent(formatdev(d));
return 0;
}