• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
10 namespace v8 {
11 namespace internal {
12 
13 class ParallelWorkItem {
14  public:
15   ParallelWorkItem() = default;
16 
TryAcquire()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  private:
26   bool acquire_{false};
27 };
28 
29 }  // namespace internal
30 }  // namespace v8
31 
32 #endif  // V8_HEAP_PARALLEL_WORK_ITEM_H_
33