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 #ifndef CONTENT_RENDERER_DEVTOOLS_LOCK_FREE_CIRCULAR_QUEUE_H_ | 5 #ifndef CONTENT_RENDERER_DEVTOOLS_LOCK_FREE_CIRCULAR_QUEUE_H_ |
6 #define CONTENT_RENDERER_DEVTOOLS_LOCK_FREE_CIRCULAR_QUEUE_H_ | 6 #define CONTENT_RENDERER_DEVTOOLS_LOCK_FREE_CIRCULAR_QUEUE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/atomicops.h" | 10 #include "base/atomicops.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/aligned_memory.h" | 12 #include "base/memory/aligned_memory.h" |
13 | 13 |
14 #define CACHELINE_ALIGNED ALIGNAS(64) | 14 #define CACHELINE_ALIGNED alignas(64) |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 MSVC_PUSH_DISABLE_WARNING(4324) // structure was padded due to align | 18 MSVC_PUSH_DISABLE_WARNING(4324) // structure was padded due to align |
19 | 19 |
20 // Lock-free cache-friendly sampling circular queue for large | 20 // Lock-free cache-friendly sampling circular queue for large |
21 // records. Intended for fast transfer of large records between a | 21 // records. Intended for fast transfer of large records between a |
22 // single producer and a single consumer. If the queue is full, | 22 // single producer and a single consumer. If the queue is full, |
23 // StartEnqueue will return nullptr. The queue is designed with | 23 // StartEnqueue will return nullptr. The queue is designed with |
24 // a goal in mind to evade cache lines thrashing by preventing | 24 // a goal in mind to evade cache lines thrashing by preventing |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 Entry* entry) { | 118 Entry* entry) { |
119 Entry* next = entry + 1; | 119 Entry* next = entry + 1; |
120 if (next == &buffer_[L]) | 120 if (next == &buffer_[L]) |
121 return buffer_; | 121 return buffer_; |
122 return next; | 122 return next; |
123 } | 123 } |
124 | 124 |
125 template <typename T, unsigned L> | 125 template <typename T, unsigned L> |
126 void* LockFreeCircularQueue<T, L>::operator new(size_t size) { | 126 void* LockFreeCircularQueue<T, L>::operator new(size_t size) { |
127 typedef LockFreeCircularQueue<T, L> QueueTypeAlias; | 127 typedef LockFreeCircularQueue<T, L> QueueTypeAlias; |
128 return base::AlignedAlloc(size, ALIGNOF(QueueTypeAlias)); | 128 return base::AlignedAlloc(size, alignof(QueueTypeAlias)); |
129 } | 129 } |
130 | 130 |
131 template <typename T, unsigned L> | 131 template <typename T, unsigned L> |
132 void LockFreeCircularQueue<T, L>::operator delete(void* ptr) { | 132 void LockFreeCircularQueue<T, L>::operator delete(void* ptr) { |
133 base::AlignedFree(ptr); | 133 base::AlignedFree(ptr); |
134 } | 134 } |
135 | 135 |
136 } // namespace content | 136 } // namespace content |
137 | 137 |
138 #endif // CONTENT_RENDERER_DEVTOOLS_LOCK_FREE_CIRCULAR_QUEUE_H_ | 138 #endif // CONTENT_RENDERER_DEVTOOLS_LOCK_FREE_CIRCULAR_QUEUE_H_ |
OLD | NEW |