Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
|
timvolodine
2016/09/23 17:34:27
pls keep the original creation date (also as in .h
| |
| 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 #include "content/common/one_writer_seqlock.h" | 5 #include "base/synchronization/one_writer_seqlock.h" |
| 6 | 6 |
| 7 namespace content { | 7 namespace base { |
| 8 | 8 |
| 9 OneWriterSeqLock::OneWriterSeqLock() | 9 OneWriterSeqLock::OneWriterSeqLock() : sequence_(0) {} |
| 10 : sequence_(0) { | |
| 11 } | |
| 12 | 10 |
| 13 base::subtle::Atomic32 OneWriterSeqLock::ReadBegin() { | 11 base::subtle::Atomic32 OneWriterSeqLock::ReadBegin() { |
| 14 base::subtle::Atomic32 version; | 12 base::subtle::Atomic32 version; |
| 15 for (;;) { | 13 for (;;) { |
| 16 version = base::subtle::NoBarrier_Load(&sequence_); | 14 version = base::subtle::NoBarrier_Load(&sequence_); |
| 17 | 15 |
| 18 // If the counter is even, then the associated data might be in a | 16 // If the counter is even, then the associated data might be in a |
| 19 // consistent state, so we can try to read. | 17 // consistent state, so we can try to read. |
| 20 if ((version & 1) == 0) | 18 if ((version & 1) == 0) |
| 21 break; | 19 break; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 39 // -- Store fence, write membarrier | 37 // -- Store fence, write membarrier |
| 40 } | 38 } |
| 41 | 39 |
| 42 void OneWriterSeqLock::WriteEnd() { | 40 void OneWriterSeqLock::WriteEnd() { |
| 43 // Increment the sequence to an even number to indicate the completion of | 41 // Increment the sequence to an even number to indicate the completion of |
| 44 // a write update. | 42 // a write update. |
| 45 // -- Store fence, write membarrier | 43 // -- Store fence, write membarrier |
| 46 base::subtle::Barrier_AtomicIncrement(&sequence_, 1); | 44 base::subtle::Barrier_AtomicIncrement(&sequence_, 1); |
| 47 } | 45 } |
| 48 | 46 |
| 49 } // namespace content | 47 } // namespace base |
| OLD | NEW |