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

Side by Side Diff: impl/memory/transaction.go

Issue 2302743002: Interface update, per-method Contexts. (Closed)
Patch Set: WithoutTransaction, comments, fixes, cleanup. Created 4 years, 3 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
OLDNEW
(Empty)
1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package memory
6
7 import (
8 "sync/atomic"
9
10 ds "github.com/luci/gae/service/datastore"
11
12 "github.com/luci/luci-go/common/errors"
13
14 "golang.org/x/net/context"
15 )
16
17 type transactionImpl struct {
18 // boolean 0 or 1, use atomic.*Int32 to access.
19 closed int32
20 isXG bool
21 }
22
23 func (ti *transactionImpl) close() error {
24 if !atomic.CompareAndSwapInt32(&ti.closed, 0, 1) {
25 return errors.New("transaction is already closed")
26 }
27 return nil
28 }
29
30 func (ti *transactionImpl) valid() error {
31 if atomic.LoadInt32(&ti.closed) == 1 {
32 return errors.New("transaction has expired")
33 }
34 return nil
35 }
36
37 func assertTxnValid(c context.Context) error {
38 t := ds.CurrentTransaction(c)
39 if t == nil {
40 return nil
41 }
42
43 return t.(*transactionImpl).valid()
44 }
OLDNEW
« no previous file with comments | « impl/memory/testing_utils_test.go ('k') | impl/memory/user.go » ('j') | impl/prod/context.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698