nusb: more locking, also close dfd

This commit is contained in:
aiju 2011-07-29 16:24:52 +02:00
parent 61d322679b
commit 7f27b397ca
2 changed files with 9 additions and 0 deletions

View file

@ -6,6 +6,7 @@
#include "fns.h" #include "fns.h"
Hub *hubs; Hub *hubs;
QLock hublock;
static int nhubs; static int nhubs;
static int mustdump; static int mustdump;
static int pollms = Pollms; static int pollms = Pollms;
@ -676,6 +677,7 @@ work(void)
* have to poll the root hub(s) in any case. * have to poll the root hub(s) in any case.
*/ */
for(;;){ for(;;){
qlock(&hublock);
Again: Again:
for(h = hubs; h != nil; h = h->next) for(h = hubs; h != nil; h = h->next)
for(i = 1; i <= h->nport; i++) for(i = 1; i <= h->nport; i++)
@ -683,6 +685,7 @@ Again:
/* changes in hub list; repeat */ /* changes in hub list; repeat */
goto Again; goto Again;
} }
qunlock(&hublock);
sleep(pollms); sleep(pollms);
if(mustdump) if(mustdump)
dump(); dump();

View file

@ -239,12 +239,16 @@ enumerate(Event **l)
static void static void
usbdopen(Req *req) usbdopen(Req *req)
{ {
extern QLock hublock;
if(req->fid->qid.path == Qusbevent){ if(req->fid->qid.path == Qusbevent){
qlock(&hublock);
qlock(&evlock); qlock(&evlock);
enumerate(&req->fid->aux); enumerate(&req->fid->aux);
((Event *)req->fid->aux)->ref++; ((Event *)req->fid->aux)->ref++;
((Event *)req->fid->aux)->prev--; ((Event *)req->fid->aux)->prev--;
qunlock(&evlock); qunlock(&evlock);
qunlock(&hublock);
} }
respond(req, nil); respond(req, nil);
} }
@ -307,6 +311,8 @@ startdev(Port *p)
fprint(2, "okay what?\n"); fprint(2, "okay what?\n");
return -1; return -1;
} }
close(d->dfd);
d->dfd = -1;
pushevent(formatdev(d)); pushevent(formatdev(d));
return 0; return 0;
} }