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

Side by Side Diff: src/circular-queue.h

Issue 2091019: CPU profiler: make code events handling scalable. (Closed)
Patch Set: Created 10 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/circular-queue-inl.h » ('j') | src/unbound-queue.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_CIRCULAR_QUEUE_H_ 28 #ifndef V8_CIRCULAR_QUEUE_H_
29 #define V8_CIRCULAR_QUEUE_H_ 29 #define V8_CIRCULAR_QUEUE_H_
30 30
31 namespace v8 { 31 namespace v8 {
32 namespace internal { 32 namespace internal {
33 33
34 34
35 // Lock-based blocking circular queue for small records. Intended for
36 // transfer of small records between a single producer and a single
37 // consumer. Blocks on enqueue operation if the queue is full.
38 template<typename Record>
39 class CircularQueue {
40 public:
41 inline explicit CircularQueue(int desired_buffer_size_in_bytes);
42 inline ~CircularQueue();
43
44 INLINE(void Dequeue(Record* rec));
45 INLINE(void Enqueue(const Record& rec));
46 INLINE(bool IsEmpty()) { return enqueue_pos_ == dequeue_pos_; }
47
48 private:
49 INLINE(Record* Next(Record* curr));
50
51 Record* buffer_;
52 Record* const buffer_end_;
53 Semaphore* enqueue_semaphore_;
54 Record* enqueue_pos_;
55 Record* dequeue_pos_;
56
57 DISALLOW_COPY_AND_ASSIGN(CircularQueue);
58 };
59
60
61 // Lock-free cache-friendly sampling circular queue for large 35 // Lock-free cache-friendly sampling circular queue for large
62 // records. Intended for fast transfer of large records between a 36 // records. Intended for fast transfer of large records between a
63 // single producer and a single consumer. If the queue is full, 37 // single producer and a single consumer. If the queue is full,
64 // previous unread records are overwritten. The queue is designed with 38 // previous unread records are overwritten. The queue is designed with
65 // a goal in mind to evade cache lines thrashing by preventing 39 // a goal in mind to evade cache lines thrashing by preventing
66 // simultaneous reads and writes to adjanced memory locations. 40 // simultaneous reads and writes to adjanced memory locations.
67 // 41 //
68 // IMPORTANT: as a producer never checks for chunks cleanness, it is 42 // IMPORTANT: as a producer never checks for chunks cleanness, it is
69 // possible that it can catch up and overwrite a chunk that a consumer 43 // possible that it can catch up and overwrite a chunk that a consumer
70 // is currently reading, resulting in a corrupt record being read. 44 // is currently reading, resulting in a corrupt record being read.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ProducerPosition* producer_pos_; 94 ProducerPosition* producer_pos_;
121 ConsumerPosition* consumer_pos_; 95 ConsumerPosition* consumer_pos_;
122 96
123 DISALLOW_COPY_AND_ASSIGN(SamplingCircularQueue); 97 DISALLOW_COPY_AND_ASSIGN(SamplingCircularQueue);
124 }; 98 };
125 99
126 100
127 } } // namespace v8::internal 101 } } // namespace v8::internal
128 102
129 #endif // V8_CIRCULAR_QUEUE_H_ 103 #endif // V8_CIRCULAR_QUEUE_H_
OLDNEW
« no previous file with comments | « no previous file | src/circular-queue-inl.h » ('j') | src/unbound-queue.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698