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

Unified Diff: Source/platform/scheduler/AtomicRingbuffer.h

Issue 439923006: Prioritizing input and compositor tasks in the blink scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months 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 | Source/platform/scheduler/Scheduler.h » ('j') | Source/platform/scheduler/Scheduler.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/scheduler/AtomicRingbuffer.h
diff --git a/Source/platform/scheduler/AtomicRingbuffer.h b/Source/platform/scheduler/AtomicRingbuffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..e0c7e3d2d89677dd4e4613e09f48e531010cd73a
--- /dev/null
+++ b/Source/platform/scheduler/AtomicRingbuffer.h
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef AtomicRingbuffer_h
+#define AtomicRingbuffer_h
+
+#include "wtf/Atomics.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/Vector.h"
+
+namespace blink {
+
+template <typename T, int size> class AtomicRingBuffer {
+ WTF_MAKE_NONCOPYABLE(AtomicRingBuffer);
+public:
+ AtomicRingBuffer() : m_writeCounter(0), m_readIndex(1)
Sami 2014/08/06 10:19:52 nit: Blink has a different style for initializers,
alexclarke 2014/08/07 12:08:06 Acknowledged.
+ {
+ m_values.resize(size);
+ for (int i = 0; i < size; i++)
+ m_values[i] = nullptr;
+ }
+
+ // May be called from any thread
+ void pushMaySpinlock(T* value)
+ {
+ int pos = atomicAdd(&m_writeCounter, 1) % size;
+ while (!atomicTestAndSwap((void* volatile*) &m_values[pos], 0, value)) {
Sami 2014/08/06 10:19:52 nit: nullptr instead of 0?
alexclarke 2014/08/07 12:08:06 Acknowledged.
+ // spin
+ }
+ }
+
+ // Returns null if there's nothing queued up. May only be called from the main thread.
+ T* pop()
+ {
+ T* value = (T*) atomicExchange((void* volatile*) &m_values[m_readIndex], nullptr);
Sami 2014/08/06 10:19:52 Please use C++-style casts instead of C ones. Is t
alexclarke 2014/08/07 12:08:06 Acknowledged.
+ if (value)
+ m_readIndex = (m_readIndex + 1) % size;
+ return value;
+ }
+
+private:
+ volatile int m_writeCounter;
Sami 2014/08/06 10:19:52 nit: m_writeIndex to match the other var?
alexclarke 2014/08/07 12:08:06 Acknowledged.
+ int m_readIndex;
+ Vector<T*> m_values;
+};
+
+} // namespace blink
+
+#endif // AtomicRingbuffer_h
« no previous file with comments | « no previous file | Source/platform/scheduler/Scheduler.h » ('j') | Source/platform/scheduler/Scheduler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698