microtask-queue.h 1.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright 2018 the V8 project 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 V8_OBJECTS_MICROTASK_QUEUE_H_
#define V8_OBJECTS_MICROTASK_QUEUE_H_

#include "src/objects.h"
#include "src/objects/microtask.h"

// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"

namespace v8 {
namespace internal {

17
class V8_EXPORT_PRIVATE MicrotaskQueue : public Struct {
18 19 20 21 22
 public:
  DECL_CAST(MicrotaskQueue)
  DECL_VERIFIER(MicrotaskQueue)
  DECL_PRINTER(MicrotaskQueue)

23 24 25 26 27 28 29 30 31 32 33 34
  // A FixedArray that the queued microtasks are stored.
  // The first |pending_microtask_count| slots contains Microtask instance
  // for each, and followings are undefined_value if any.
  DECL_ACCESSORS(queue, FixedArray)

  // The number of microtasks queued in |queue|. This must be less or equal to
  // the length of |queue|.
  DECL_INT_ACCESSORS(pending_microtask_count)

  // Enqueues |microtask| to |microtask_queue|.
  static void EnqueueMicrotask(Isolate* isolate,
                               Handle<MicrotaskQueue> microtask_queue,
35
                               Handle<Microtask> microtask);
36 37

  // Runs all enqueued microtasks.
38 39
  static void RunMicrotasks(Handle<MicrotaskQueue> microtask_queue);

40 41 42 43 44
  static constexpr int kMinimumQueueCapacity = 8;

  static const int kQueueOffset = HeapObject::kHeaderSize;
  static const int kPendingMicrotaskCountOffset = kQueueOffset + kPointerSize;
  static const int kSize = kPendingMicrotaskCountOffset + kPointerSize;
45 46 47 48 49 50 51 52 53 54 55

 private:
  DISALLOW_IMPLICIT_CONSTRUCTORS(MicrotaskQueue);
};

}  // namespace internal
}  // namespace v8

#include "src/objects/object-macros-undef.h"

#endif  // V8_OBJECTS_MICROTASK_QUEUE_H_