Browse Source

Plan 9 from Bell Labs 2004-01-06

David du Colombier 20 years ago
parent
commit
8ce54fb8f3
5 changed files with 52 additions and 21 deletions
  1. 3 3
      dist/replica/plan9.db
  2. 3 0
      dist/replica/plan9.log
  3. 44 17
      sys/src/9/port/portclock.c
  4. 1 0
      sys/src/9/port/portdat.h
  5. 1 1
      sys/src/cmd/nm.c

+ 3 - 3
dist/replica/plan9.db

@@ -5449,8 +5449,8 @@ sys/src/9/port/nulledf.c - 664 sys sys 1037669300 821
 sys/src/9/port/page.c - 664 sys sys 1055688510 8107
 sys/src/9/port/parse.c - 664 sys sys 1014931177 2026
 sys/src/9/port/pgrp.c - 664 sys sys 1072704671 3940
-sys/src/9/port/portclock.c - 664 sys sys 1072704672 4294
-sys/src/9/port/portdat.h - 664 sys sys 1072704671 22700
+sys/src/9/port/portclock.c - 664 sys sys 1073323995 4758
+sys/src/9/port/portdat.h - 664 sys sys 1073324006 22707
 sys/src/9/port/portfns.h - 664 sys sys 1068215525 11376
 sys/src/9/port/portmkfile - 664 sys sys 1067722766 2098
 sys/src/9/port/print.c - 664 sys sys 1014931178 227
@@ -9744,7 +9744,7 @@ sys/src/cmd/ndb/time.c - 664 sys sys 957402055 321
 sys/src/cmd/netstat.c - 664 sys sys 1063854991 3794
 sys/src/cmd/news.c - 664 sys sys 1014926614 3778
 sys/src/cmd/nfs.c - 664 sys sys 1050068720 31096
-sys/src/cmd/nm.c - 664 sys sys 1014926696 4908
+sys/src/cmd/nm.c - 664 sys sys 1073313392 4912
 sys/src/cmd/nntpfs.c - 664 sys sys 1055699250 18903
 sys/src/cmd/ns.c - 664 sys sys 984717934 3558
 sys/src/cmd/p.c - 664 sys sys 1043516305 1497

+ 3 - 0
dist/replica/plan9.log

@@ -13273,3 +13273,6 @@
 1073151086 0 c sys/src/cmd/history.c - 664 sys sys 1073079763 6117
 1073151086 1 c sys/src/cmd/fossil/file.c - 664 sys sys 1073140359 30215
 1073269923 0 c sys/src/cmd/rio/wind.c - 664 sys sys 1073268477 32704
+1073314930 0 c sys/src/cmd/nm.c - 664 sys sys 1073313392 4912
+1073325731 0 c sys/src/9/port/portclock.c - 664 sys sys 1073323995 4758
+1073325731 1 c sys/src/9/port/portdat.h - 664 sys sys 1073324006 22707

+ 44 - 17
sys/src/9/port/portclock.c

@@ -64,6 +64,29 @@ tadd(Timers *tt, Timer *nt)
 	return 0;
 }
 
+static uvlong
+tdel(Timer *dt)
+{
+
+	Timer *t, **last;
+	Timers *tt;
+
+	tt = dt->tt;
+	if (tt == nil)
+		return 0;
+	for(last = &tt->head; t = *last; last = &t->tnext){
+		if(t == dt){
+			assert(dt->tt);
+			dt->tt = nil;
+			*last = t->tnext;
+			break;
+		}
+	}
+	if(last == &tt->head && tt->head)
+		return tt->head->twhen;
+	return 0;
+}
+
 /* add or modify a timer */
 void
 timeradd(Timer *nt)
@@ -80,40 +103,38 @@ timeradd(Timer *nt)
 			nt->tns = when;
 		}
 	}
-	if (nt->tt)
-		timerdel(nt);
+	/* Must lock Timer struct before Timers struct */
+	ilock(nt);
+	if(tt = nt->tt){
+		ilock(tt);
+		tdel(nt);
+		iunlock(tt);
+	}
 	tt = &timers[m->machno];
 	ilock(tt);
 	when = tadd(tt, nt);
 	if(when)
 		timerset(when);
 	iunlock(tt);
+	iunlock(nt);
 }
 
+
 void
 timerdel(Timer *dt)
 {
-	Timer *t, **last;
 	Timers *tt;
+	uvlong when;
 
-	while(tt = dt->tt){
+	ilock(dt);
+	if(tt = dt->tt){
 		ilock(tt);
-		if (tt != dt->tt){
-			iunlock(tt);
-			continue;
-		}
-		for(last = &tt->head; t = *last; last = &t->tnext){
-			if(t == dt){
-				assert(dt->tt);
-				dt->tt = nil;
-				*last = t->tnext;
-				break;
-			}
-		}
-		if(last == &tt->head && tt->head)
+		when = tdel(dt);
+		if(when && tt == &timers[m->machno])
 			timerset(tt->head->twhen);
 		iunlock(tt);
 	}
+	iunlock(dt);
 }
 
 void
@@ -167,6 +188,12 @@ timerintr(Ureg *u, uvlong)
 	now = fastticks(nil);
 	ilock(tt);
 	while(t = tt->head){
+		/*
+		 * No need to ilock t here: any manipulation of t
+		 * requires tdel(t) and this must be done with a
+		 * lock to tt held.  We have tt, so the tdel will
+		 * wait until we're done
+		 */
 		when = t->twhen;
 		if(when > now){
 			timerset(when);

+ 1 - 0
sys/src/9/port/portdat.h

@@ -515,6 +515,7 @@ struct Timer
 	void	(*tf)(Ureg*, Timer*);
 	void	*ta;
 	/* Internal */
+	Lock;
 	Timers	*tt;		/* Timers queue this timer runs on */
 	uvlong	twhen;		/* ns represented in fastticks */
 	Timer	*tnext;

+ 1 - 1
sys/src/cmd/nm.c

@@ -158,7 +158,7 @@ zenter(Sym *s)
 
 	if (s->value > maxf) {
 		maxf = (s->value+CHUNK-1) &~ (CHUNK-1);
-		fnames = realloc(fnames, maxf*sizeof(*fnames));
+		fnames = realloc(fnames, (maxf+1)*sizeof(*fnames));
 		if(fnames == 0) {
 			error("out of memory", argv0);
 			exits("memory");