V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
microtask-queue.h
1 // Copyright 2018 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_MICROTASK_QUEUE_H_
6 #define V8_MICROTASK_QUEUE_H_
7 
8 #include <stdint.h>
9 #include <memory>
10 
11 #include "src/base/macros.h"
12 
13 namespace v8 {
14 namespace internal {
15 
16 class Isolate;
17 class Microtask;
18 class Object;
19 class RootVisitor;
20 
21 class V8_EXPORT_PRIVATE MicrotaskQueue {
22  public:
23  static void SetUpDefaultMicrotaskQueue(Isolate* isolate);
24  static std::unique_ptr<MicrotaskQueue> New(Isolate* isolate);
25 
26  ~MicrotaskQueue();
27 
28  static Object* CallEnqueueMicrotask(Isolate* isolate,
29  intptr_t microtask_queue_pointer,
30  Microtask* microtask);
31 
32  void EnqueueMicrotask(Microtask* microtask);
33 
34  // Returns -1 if the execution is terminating, otherwise, returns 0.
35  // TODO(tzik): Update the implementation to return the number of processed
36  // microtasks.
37  int RunMicrotasks(Isolate* isolate);
38 
39  // Iterate all pending Microtasks in this queue as strong roots, so that
40  // builtins can update the queue directly without the write barrier.
41  void IterateMicrotasks(RootVisitor* visitor);
42 
43  intptr_t capacity() const { return capacity_; }
44  intptr_t size() const { return size_; }
45  intptr_t start() const { return start_; }
46 
47  MicrotaskQueue* next() const { return next_; }
48  MicrotaskQueue* prev() const { return prev_; }
49 
50  static const size_t kRingBufferOffset;
51  static const size_t kCapacityOffset;
52  static const size_t kSizeOffset;
53  static const size_t kStartOffset;
54 
55  static const intptr_t kMinimumCapacity;
56 
57  private:
59  void ResizeBuffer(intptr_t new_capacity);
60 
61  // MicrotaskQueue instances form a doubly linked list loop, so that all
62  // instances are reachable through |next_|.
63  MicrotaskQueue* next_ = nullptr;
64  MicrotaskQueue* prev_ = nullptr;
65 
66  // A ring buffer to hold Microtask instances.
67  // ring_buffer_[(start_ + i) % capacity_] contains |i|th Microtask for each
68  // |i| in [0, size_).
69  Object** ring_buffer_ = nullptr;
70  intptr_t capacity_ = 0;
71  intptr_t size_ = 0;
72  intptr_t start_ = 0;
73 };
74 
75 } // namespace internal
76 } // namespace v8
77 
78 #endif // V8_MICROTASK_QUEUE_H_
Definition: libplatform.h:13