diff options
author | Russ Cox <rsc@golang.org> | 2014-11-05 14:42:54 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-11-05 14:42:54 -0500 |
commit | aefaeb75f3eff323f212c5309d8ae65768ad9809 (patch) | |
tree | e98106c105e31954ab9b0b4775fd68afe23fe53c /src/cmd/gc/walk.c | |
parent | 6d5e8c9c938b45ddcc62470a790408642a26218b (diff) | |
download | go-aefaeb75f3eff323f212c5309d8ae65768ad9809.tar.gz |
[dev.garbage] cmd/gc, runtime: add locks around print statements
Now each C printf, Go print, or Go println is guaranteed
not to be interleaved with other calls of those functions.
This should help when debugging concurrent failures.
LGTM=rlh
R=rlh
CC=golang-codereviews
https://codereview.appspot.com/169120043
Diffstat (limited to 'src/cmd/gc/walk.c')
-rw-r--r-- | src/cmd/gc/walk.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index 7b502eb60..38bed1e22 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -364,6 +364,15 @@ walkexprlistsafe(NodeList *l, NodeList **init) } void +walkexprlistcheap(NodeList *l, NodeList **init) +{ + for(; l; l=l->next) { + l->n = cheapexpr(l->n, init); + walkexpr(&l->n, init); + } +} + +void walkexpr(Node **np, NodeList **init) { Node *r, *l, *var, *a; @@ -1773,6 +1782,11 @@ walkprint(Node *nn, NodeList **init) calls = nil; notfirst = 0; + // Hoist all the argument evaluation up before the lock. + walkexprlistcheap(all, init); + + calls = list(calls, mkcall("printlock", T, init)); + for(l=all; l; l=l->next) { if(notfirst) { calls = list(calls, mkcall("printsp", T, init)); @@ -1853,6 +1867,9 @@ walkprint(Node *nn, NodeList **init) if(op == OPRINTN) calls = list(calls, mkcall("printnl", T, nil)); + + calls = list(calls, mkcall("printunlock", T, init)); + typechecklist(calls, Etop); walkexprlist(calls, init); |