Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: appengine/memlock/memlock.go

Issue 1679023005: Add Context cancellation to clock. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Cleanup memlock, restore old determinism, better name. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | common/clock/clock.go » ('j') | common/clock/testclock/testclock.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Package memlock allows multiple appengine handlers to coordinate best-effort 5 // Package memlock allows multiple appengine handlers to coordinate best-effort
6 // mutual execution via memcache. "best-effort" here means "best-effort"... 6 // mutual execution via memcache. "best-effort" here means "best-effort"...
7 // memcache is not reliable. However, colliding on memcache is a lot cheaper 7 // memcache is not reliable. However, colliding on memcache is a lot cheaper
8 // than, for example, colliding with datastore transactions. 8 // than, for example, colliding with datastore transactions.
9 package memlock 9 package memlock
10 10
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 testStopCB, _ := ctx.Value(testStopCBKey).(func()) 145 testStopCB, _ := ctx.Value(testStopCBKey).(func())
146 146
147 // This goroutine checks to see if we still posess the lock, and refresh es it 147 // This goroutine checks to see if we still posess the lock, and refresh es it
148 // if we do. 148 // if we do.
149 go func() { 149 go func() {
150 defer func() { 150 defer func() {
151 cancelFunc() 151 cancelFunc()
152 close(finished) 152 close(finished)
153 }() 153 }()
154 154
155 checkLoop:
156 for { 155 for {
157 » » » select { 156 » » » if (<-clock.After(subCtx, delay)).Err != nil {
dnj (Google) 2016/02/10 03:40:08 Nice, eh?
158 » » » case <-subCtx.Done(): 157 » » » » break
159 » » » » break checkLoop
160 » » » case <-clock.Get(ctx).After(delay):
161 } 158 }
162 if !checkAnd(refresh) { 159 if !checkAnd(refresh) {
163 log.Warningf("lost lock: %s", err) 160 log.Warningf("lost lock: %s", err)
164 return 161 return
165 } 162 }
166 } 163 }
167 164
168 if testStopCB != nil { 165 if testStopCB != nil {
169 testStopCB() 166 testStopCB()
170 } 167 }
171 checkAnd(release) 168 checkAnd(release)
172 }() 169 }()
173 170
174 return f(subCtx) 171 return f(subCtx)
175 } 172 }
OLDNEW
« no previous file with comments | « no previous file | common/clock/clock.go » ('j') | common/clock/testclock/testclock.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698