OLD | NEW |
(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 } |
OLD | NEW |