v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
parallel-work-item.h
Go to the documentation of this file.
1// Copyright 2020 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_HEAP_PARALLEL_WORK_ITEM_H_
6#define V8_HEAP_PARALLEL_WORK_ITEM_H_
7
8#include <atomic>
9
10namespace v8 {
11namespace internal {
12
14 public:
15 ParallelWorkItem() = default;
16
17 bool TryAcquire() {
18 // memory_order_relaxed is sufficient as the work item's state itself hasn't
19 // been modified since the beginning of its associated job. This is only
20 // atomically acquiring the right to work on it.
21 return reinterpret_cast<std::atomic<bool>*>(&acquire_)->exchange(
22 true, std::memory_order_relaxed) == false;
23 }
24
25 bool IsAcquired() const {
26 return reinterpret_cast<const std::atomic<bool>*>(&acquire_)->load(
27 std::memory_order_relaxed);
28 }
29
30 private:
31 bool acquire_{false};
32};
33
34} // namespace internal
35} // namespace v8
36
37#endif // V8_HEAP_PARALLEL_WORK_ITEM_H_