| OLD | NEW |
| 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 memory | 5 package memory |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "encoding/binary" | 8 "encoding/binary" |
| 9 "sync" | 9 "sync" |
| 10 "time" | 10 "time" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 200 } |
| 201 | 201 |
| 202 func (m *memcacheImpl) AddMulti(items []mc.Item, cb mc.RawCB) error { | 202 func (m *memcacheImpl) AddMulti(items []mc.Item, cb mc.RawCB) error { |
| 203 now := clock.Now(m.ctx) | 203 now := clock.Now(m.ctx) |
| 204 doCBs(items, cb, func(itm mc.Item) error { | 204 doCBs(items, cb, func(itm mc.Item) error { |
| 205 m.data.lock.Lock() | 205 m.data.lock.Lock() |
| 206 defer m.data.lock.Unlock() | 206 defer m.data.lock.Unlock() |
| 207 if !m.data.hasItemLocked(now, itm.Key()) { | 207 if !m.data.hasItemLocked(now, itm.Key()) { |
| 208 m.data.setItemLocked(now, itm) | 208 m.data.setItemLocked(now, itm) |
| 209 return nil | 209 return nil |
| 210 } else { | |
| 211 return mc.ErrNotStored | |
| 212 } | 210 } |
| 211 return mc.ErrNotStored |
| 213 }) | 212 }) |
| 214 return nil | 213 return nil |
| 215 } | 214 } |
| 216 | 215 |
| 217 func (m *memcacheImpl) CompareAndSwapMulti(items []mc.Item, cb mc.RawCB) error { | 216 func (m *memcacheImpl) CompareAndSwapMulti(items []mc.Item, cb mc.RawCB) error { |
| 218 now := clock.Now(m.ctx) | 217 now := clock.Now(m.ctx) |
| 219 doCBs(items, cb, func(itm mc.Item) error { | 218 doCBs(items, cb, func(itm mc.Item) error { |
| 220 m.data.lock.Lock() | 219 m.data.lock.Lock() |
| 221 defer m.data.lock.Unlock() | 220 defer m.data.lock.Unlock() |
| 222 | 221 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 return cur, nil | 342 return cur, nil |
| 344 } | 343 } |
| 345 | 344 |
| 346 func (m *memcacheImpl) Stats() (*mc.Statistics, error) { | 345 func (m *memcacheImpl) Stats() (*mc.Statistics, error) { |
| 347 m.data.lock.RLock() | 346 m.data.lock.RLock() |
| 348 defer m.data.lock.RUnlock() | 347 defer m.data.lock.RUnlock() |
| 349 | 348 |
| 350 ret := m.data.stats | 349 ret := m.data.stats |
| 351 return &ret, nil | 350 return &ret, nil |
| 352 } | 351 } |
| OLD | NEW |