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

Unified Diff: impl/memory/transaction.go

Issue 2302743002: Interface update, per-method Contexts. (Closed)
Patch Set: Lightning talk licenses. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/testing_utils_test.go ('k') | impl/memory/user.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/transaction.go
diff --git a/impl/memory/transaction.go b/impl/memory/transaction.go
new file mode 100644
index 0000000000000000000000000000000000000000..5b0f44c24d8e7ad65c682ce706ea85bc266a88b0
--- /dev/null
+++ b/impl/memory/transaction.go
@@ -0,0 +1,44 @@
+// Copyright 2015 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package memory
+
+import (
+ "sync/atomic"
+
+ ds "github.com/luci/gae/service/datastore"
+
+ "github.com/luci/luci-go/common/errors"
+
+ "golang.org/x/net/context"
+)
+
+type transactionImpl struct {
+ // boolean 0 or 1, use atomic.*Int32 to access.
+ closed int32
+ isXG bool
+}
+
+func (ti *transactionImpl) close() error {
+ if !atomic.CompareAndSwapInt32(&ti.closed, 0, 1) {
+ return errors.New("transaction is already closed")
+ }
+ return nil
+}
+
+func (ti *transactionImpl) valid() error {
+ if atomic.LoadInt32(&ti.closed) == 1 {
+ return errors.New("transaction has expired")
+ }
+ return nil
+}
+
+func assertTxnValid(c context.Context) error {
+ t := ds.CurrentTransaction(c)
+ if t == nil {
+ return nil
+ }
+
+ return t.(*transactionImpl).valid()
+}
« no previous file with comments | « impl/memory/testing_utils_test.go ('k') | impl/memory/user.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698