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

Side by Side Diff: device/base/synchronization/one_writer_seqlock.h

Issue 2273703002: Force events to be non blocking if main thread is unresponsive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Histogram nits Created 4 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef DEVICE_BASE_SYNCHRONIZATION_ONE_WRITER_SEQLOCK_H_ 5 #ifndef DEVICE_BASE_SYNCHRONIZATION_ONE_WRITER_SEQLOCK_H_
6 #define DEVICE_BASE_SYNCHRONIZATION_ONE_WRITER_SEQLOCK_H_ 6 #define DEVICE_BASE_SYNCHRONIZATION_ONE_WRITER_SEQLOCK_H_
7 7
8 #include "base/atomicops.h" 8 #include "base/atomicops.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/threading/platform_thread.h" 10 #include "base/threading/platform_thread.h"
11 11
12 namespace device { 12 namespace device {
13 13
14 // This SeqLock handles only *one* writer and multiple readers. It may be 14 // This SeqLock handles only *one* writer and multiple readers. It may be
15 // suitable for low-contention with relatively infrequent writes, and many 15 // suitable for low-contention with relatively infrequent writes, and many
16 // readers. See: 16 // readers. See:
17 // http://en.wikipedia.org/wiki/Seqlock 17 // http://en.wikipedia.org/wiki/Seqlock
18 // http://www.concurrencykit.org/doc/ck_sequence.html 18 // http://www.concurrencykit.org/doc/ck_sequence.html
19 // This implementation is based on ck_sequence.h from http://concurrencykit.org. 19 // This implementation is based on ck_sequence.h from http://concurrencykit.org.
20 // 20 //
21 // Currently this type of lock is used in two implementations (gamepad and 21 // Currently this type of lock is used in at least two implementations (gamepad
22 // device motion, in particular see e.g. shared_memory_seqlock_buffer.h). 22 // and device motion, in particular see e.g. shared_memory_seqlock_buffer.h).
23 // It may make sense to generalize this lock to multiple writers. 23 // It may make sense to generalize this lock to multiple writers.
24 // 24 //
25 // You must be very careful not to operate on potentially inconsistent read 25 // You must be very careful not to operate on potentially inconsistent read
26 // buffers. If the read must be retry'd, the data in the read buffer could 26 // buffers. If the read must be retry'd, the data in the read buffer could
27 // contain any random garbage. e.g., contained pointers might be 27 // contain any random garbage. e.g., contained pointers might be
28 // garbage, or indices could be out of range. Probably the only suitable thing 28 // garbage, or indices could be out of range. Probably the only suitable thing
29 // to do during the read loop is to make a copy of the data, and operate on it 29 // to do during the read loop is to make a copy of the data, and operate on it
30 // only after the read was found to be consistent. 30 // only after the read was found to be consistent.
31 class OneWriterSeqLock { 31 class OneWriterSeqLock {
32 public: 32 public:
33 OneWriterSeqLock(); 33 OneWriterSeqLock();
34 base::subtle::Atomic32 ReadBegin() const; 34 base::subtle::Atomic32 ReadBegin() const;
35 void TryRead(bool* can_read, base::subtle::Atomic32* version) const;
35 bool ReadRetry(base::subtle::Atomic32 version) const; 36 bool ReadRetry(base::subtle::Atomic32 version) const;
36 void WriteBegin(); 37 void WriteBegin();
37 void WriteEnd(); 38 void WriteEnd();
38 39
39 private: 40 private:
40 base::subtle::Atomic32 sequence_; 41 base::subtle::Atomic32 sequence_;
41 DISALLOW_COPY_AND_ASSIGN(OneWriterSeqLock); 42 DISALLOW_COPY_AND_ASSIGN(OneWriterSeqLock);
42 }; 43 };
43 44
44 } // namespace device 45 } // namespace device
45 46
46 #endif // DEVICE_BASE_SYNCHRONIZATION_ONE_WRITER_SEQLOCK_H_ 47 #endif // DEVICE_BASE_SYNCHRONIZATION_ONE_WRITER_SEQLOCK_H_
OLDNEW
« no previous file with comments | « content/renderer/render_widget_unittest.cc ('k') | device/base/synchronization/one_writer_seqlock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698