From 4b5766580559d101dd1c29cc575b3ffa9f51c2d7 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 23 Sep 2013 23:16:25 +0200 Subject: fossil: move from liboventi to libthread and libventi R=rsc https://codereview.appspot.com/13504049 --- src/cmd/fossil/9lstn.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'src/cmd/fossil/9lstn.c') diff --git a/src/cmd/fossil/9lstn.c b/src/cmd/fossil/9lstn.c index 9ba508f4..b4023e8b 100644 --- a/src/cmd/fossil/9lstn.c +++ b/src/cmd/fossil/9lstn.c @@ -14,7 +14,7 @@ struct Lstn { }; static struct { - VtLock* lock; + RWLock lock; Lstn* head; Lstn* tail; @@ -23,7 +23,7 @@ static struct { static void lstnFree(Lstn* lstn) { - vtLock(lbox.lock); + wlock(&lbox.lock); if(lstn->prev != nil) lstn->prev->next = lstn->next; else @@ -32,12 +32,12 @@ lstnFree(Lstn* lstn) lstn->next->prev = lstn->prev; else lbox.tail = lstn->prev; - vtUnlock(lbox.lock); + wunlock(&lbox.lock); if(lstn->afd != -1) close(lstn->afd); - vtMemFree(lstn->address); - vtMemFree(lstn); + vtfree(lstn->address); + vtfree(lstn); } static void @@ -47,7 +47,7 @@ lstnListen(void* a) int dfd, lfd; char newdir[NETPATHLEN]; - vtThreadSetName("listen"); + threadsetname("listen"); lstn = a; for(;;){ @@ -71,24 +71,24 @@ lstnAlloc(char* address, int flags) Lstn *lstn; char dir[NETPATHLEN]; - vtLock(lbox.lock); + wlock(&lbox.lock); for(lstn = lbox.head; lstn != nil; lstn = lstn->next){ if(strcmp(lstn->address, address) != 0) continue; - vtSetError("listen: already serving '%s'", address); - vtUnlock(lbox.lock); + werrstr("listen: already serving '%s'", address); + wunlock(&lbox.lock); return nil; } if((afd = announce(address, dir)) < 0){ - vtSetError("listen: announce '%s': %r", address); - vtUnlock(lbox.lock); + werrstr("listen: announce '%s': %r", address); + wunlock(&lbox.lock); return nil; } - lstn = vtMemAllocZ(sizeof(Lstn)); + lstn = vtmallocz(sizeof(Lstn)); lstn->afd = afd; - lstn->address = vtStrDup(address); + lstn->address = vtstrdup(address); lstn->flags = flags; memmove(lstn->dir, dir, NETPATHLEN); @@ -101,10 +101,10 @@ lstnAlloc(char* address, int flags) lstn->prev = nil; } lbox.tail = lstn; - vtUnlock(lbox.lock); + wunlock(&lbox.lock); - if(vtThread(lstnListen, lstn) < 0){ - vtSetError("listen: thread '%s': %r", lstn->address); + if(proccreate(lstnListen, lstn, STACK) < 0){ + werrstr("listen: thread '%s': %r", lstn->address); lstnFree(lstn); return nil; } @@ -139,10 +139,10 @@ cmdLstn(int argc, char* argv[]) default: return cliError(usage); case 0: - vtRLock(lbox.lock); + rlock(&lbox.lock); for(lstn = lbox.head; lstn != nil; lstn = lstn->next) consPrint("\t%s\t%s\n", lstn->address, lstn->dir); - vtRUnlock(lbox.lock); + runlock(&lbox.lock); break; case 1: if(!dflag){ @@ -151,7 +151,7 @@ cmdLstn(int argc, char* argv[]) break; } - vtLock(lbox.lock); + wlock(&lbox.lock); for(lstn = lbox.head; lstn != nil; lstn = lstn->next){ if(strcmp(lstn->address, argv[0]) != 0) continue; @@ -161,10 +161,10 @@ cmdLstn(int argc, char* argv[]) } break; } - vtUnlock(lbox.lock); + wunlock(&lbox.lock); if(lstn == nil){ - vtSetError("listen: '%s' not found", argv[0]); + werrstr("listen: '%s' not found", argv[0]); return 0; } break; @@ -176,8 +176,6 @@ cmdLstn(int argc, char* argv[]) int lstnInit(void) { - lbox.lock = vtLockAlloc(); - cliAddCmd("listen", cmdLstn); return 1; -- cgit v1.2.3