ref: 908d76b563e098b0eecd7d6eea94a293fcf83389
parent: d15f7e8312cded0cfbbe184d7bc36dd98b7983a2
author: aiju <aiju@phicode.de>
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;
}
--
⑨