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

Unified Diff: impl/memory/context.go

Issue 1494223002: Add API to allow you to get the non-transactional datastore or taskqueue. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix doc and naming Created 5 years 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 | « no previous file | impl/memory/datastore.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/context.go
diff --git a/impl/memory/context.go b/impl/memory/context.go
index 6108e02cbdcbfac51122f37dd97b7dbe2df2b48c..496a343a63d1900ad74f9aed0a2b71a2690ecc3c 100644
--- a/impl/memory/context.go
+++ b/impl/memory/context.go
@@ -25,10 +25,10 @@ type memContextObj interface {
type memContext []memContextObj
-var _ = memContextObj((memContext)(nil))
+var _ memContextObj = (*memContext)(nil)
-func newMemContext(aid string) memContext {
- return memContext{
+func newMemContext(aid string) *memContext {
+ return &memContext{
newTaskQueueData(),
newDataStoreData(aid),
}
@@ -41,50 +41,50 @@ const (
memContextDSIdx
)
-func (m memContext) Get(itm memContextIdx) memContextObj {
- return m[itm]
+func (m *memContext) Get(itm memContextIdx) memContextObj {
+ return (*m)[itm]
}
-func (m memContext) Lock() {
- for _, itm := range m {
+func (m *memContext) Lock() {
+ for _, itm := range *m {
itm.Lock()
}
}
-func (m memContext) Unlock() {
- for i := len(m) - 1; i >= 0; i-- {
- m[i].Unlock()
+func (m *memContext) Unlock() {
+ for i := len(*m) - 1; i >= 0; i-- {
+ (*m)[i].Unlock()
}
}
-func (m memContext) endTxn() {
- for _, itm := range m {
+func (m *memContext) endTxn() {
+ for _, itm := range *m {
itm.endTxn()
}
}
-func (m memContext) mkTxn(o *ds.TransactionOptions) memContextObj {
- ret := make(memContext, len(m))
- for i, itm := range m {
+func (m *memContext) mkTxn(o *ds.TransactionOptions) memContextObj {
+ ret := make(memContext, len(*m))
+ for i, itm := range *m {
ret[i] = itm.mkTxn(o)
}
- return ret
+ return &ret
}
-func (m memContext) canApplyTxn(txnCtxObj memContextObj) bool {
- txnCtx := txnCtxObj.(memContext)
- for i := range m {
- if !m[i].canApplyTxn(txnCtx[i]) {
+func (m *memContext) canApplyTxn(txnCtxObj memContextObj) bool {
+ txnCtx := *txnCtxObj.(*memContext)
+ for i := range *m {
+ if !(*m)[i].canApplyTxn(txnCtx[i]) {
return false
}
}
return true
}
-func (m memContext) applyTxn(c context.Context, txnCtxObj memContextObj) {
- txnCtx := txnCtxObj.(memContext)
- for i := range m {
- m[i].applyTxn(c, txnCtx[i])
+func (m *memContext) applyTxn(c context.Context, txnCtxObj memContextObj) {
+ txnCtx := *txnCtxObj.(*memContext)
+ for i := range *m {
+ (*m)[i].applyTxn(c, txnCtx[i])
}
}
@@ -113,20 +113,30 @@ func UseWithAppID(c context.Context, aid string) context.Context {
if c.Value(memContextKey) != nil {
panic(errors.New("memory.Use: called twice on the same Context"))
}
- c = context.WithValue(
- context.WithValue(c, memContextKey, newMemContext(aid)),
- giContextKey, &globalInfoData{appid: aid})
+ memctx := newMemContext(aid)
+ c = context.WithValue(c, memContextKey, memctx)
+ c = context.WithValue(c, memContextNoTxnKey, memctx)
+ c = context.WithValue(c, giContextKey, &globalInfoData{appid: aid})
+
return useTQ(useRDS(useMC(useGI(c, aid))))
}
-func cur(c context.Context) (p memContext) {
- p, _ = c.Value(memContextKey).(memContext)
+func cur(c context.Context) (p *memContext) {
+ p, _ = c.Value(memContextKey).(*memContext)
+ return
+}
+
+func curNoTxn(c context.Context) (p *memContext) {
+ p, _ = c.Value(memContextNoTxnKey).(*memContext)
return
}
type memContextKeyType int
-var memContextKey memContextKeyType
+var (
+ memContextKey memContextKeyType
+ memContextNoTxnKey memContextKeyType = 1
+)
// weird stuff
« no previous file with comments | « no previous file | impl/memory/datastore.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698