mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8374677: ZGC: Convert zArray to use Atomic<T>
Reviewed-by: stefank, tschatzl
This commit is contained in:
parent
37cb22826a
commit
319e21e9b4
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,7 +26,7 @@
|
||||
|
||||
#include "cppstdlib/type_traits.hpp"
|
||||
#include "memory/allocation.hpp"
|
||||
#include "runtime/atomicAccess.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "runtime/thread.hpp"
|
||||
#include "utilities/growableArray.hpp"
|
||||
@ -78,7 +78,9 @@ public:
|
||||
template <typename T, bool Parallel>
|
||||
class ZArrayIteratorImpl : public StackObj {
|
||||
private:
|
||||
size_t _next;
|
||||
using NextType = std::conditional_t<Parallel, Atomic<size_t>, size_t>;
|
||||
|
||||
NextType _next;
|
||||
const size_t _end;
|
||||
const T* const _array;
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,7 +27,6 @@
|
||||
#include "gc/z/zArray.hpp"
|
||||
|
||||
#include "gc/z/zLock.inline.hpp"
|
||||
#include "runtime/atomicAccess.hpp"
|
||||
|
||||
template <typename T>
|
||||
ZArraySlice<T>::ZArraySlice(T* data, int len)
|
||||
@ -130,7 +129,7 @@ inline bool ZArrayIteratorImpl<T, Parallel>::next_serial(size_t* index) {
|
||||
|
||||
template <typename T, bool Parallel>
|
||||
inline bool ZArrayIteratorImpl<T, Parallel>::next_parallel(size_t* index) {
|
||||
const size_t claimed_index = AtomicAccess::fetch_then_add(&_next, 1u, memory_order_relaxed);
|
||||
const size_t claimed_index = _next.fetch_then_add(1u, memory_order_relaxed);
|
||||
|
||||
if (claimed_index < _end) {
|
||||
*index = claimed_index;
|
||||
@ -177,7 +176,7 @@ inline bool ZArrayIteratorImpl<T, Parallel>::next_if(T* elem, Function predicate
|
||||
|
||||
template <typename T, bool Parallel>
|
||||
inline bool ZArrayIteratorImpl<T, Parallel>::next_index(size_t* index) {
|
||||
if (Parallel) {
|
||||
if constexpr (Parallel) {
|
||||
return next_parallel(index);
|
||||
} else {
|
||||
return next_serial(index);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user