Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1660)

Unified Diff: 2014/readability/close-cond-bad.go

Issue 176660043: code review 176660043: x/talks/2014/readability: talk for GoCon 2014 autumn in...
Patch Set: diff -r 05bdda42259e https://code.google.com/p/go.talks/ Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « 2014/readability.slide ('k') | 2014/readability/close-cond-good.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: 2014/readability/close-cond-bad.go
===================================================================
new file mode 100644
--- /dev/null
+++ b/2014/readability/close-cond-bad.go
@@ -0,0 +1,26 @@
+package sample // OMIT
+type Stream struct {
+ // some fields
+ isConnClosed bool
+ connClosedCond *sync.Cond
+ connClosedLocker sync.Mutex
+}
+
+func (s *Stream) Wait() error {
+ s.connClosedCond.L.Lock()
+ for !s.isConnClosed {
+ s.connClosedCond.Wait()
+ }
+ s.connClosedCond.L.Unlock()
+ // some code
+}
+func (s *Stream) Close() {
+ // some code
+ s.connClosedCond.L.Lock()
+ s.isConnClosed = true
+ s.connClosedCond.L.Unlock()
+ s.connClosedCond.Broadcast()
+}
+func (s *Stream) IsClosed() bool {
+ return s.isConnClosed
+}
« no previous file with comments | « 2014/readability.slide ('k') | 2014/readability/close-cond-good.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b