Path: blob/master/src/hotspot/share/jfr/utilities/jfrConcurrentQueue.inline.hpp
41149 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_UTILITIES_JFRCONCURRENTQUEUE_INLINE_HPP25#define SHARE_JFR_UTILITIES_JFRCONCURRENTQUEUE_INLINE_HPP2627#include "jfr/utilities/jfrConcurrentQueue.hpp"2829#include "jfr/utilities/jfrConcurrentLinkedListHost.inline.hpp"30#include "jfr/utilities/jfrVersionSystem.inline.hpp"3132template <typename NodeType, typename AllocPolicy>33JfrConcurrentQueue<NodeType, AllocPolicy>::JfrConcurrentQueue() : _list(NULL), _head(), _last(), _tail(), _version_system() {34_head._next = const_cast<NodePtr>(&_tail);35_last._next = const_cast<NodePtr>(&_tail);36}3738template <typename NodeType, typename AllocPolicy>39bool JfrConcurrentQueue<NodeType, AllocPolicy>::initialize() {40assert(_list == NULL, "invariant");41_list = new JfrConcurrentLinkedListHost<JfrConcurrentQueue<NodeType, AllocPolicy>, HeadNode, AllocPolicy>(this);42return _list != NULL && _list->initialize();43}4445template <typename NodeType, typename AllocPolicy>46inline bool JfrConcurrentQueue<NodeType, AllocPolicy>::is_empty() const {47return Atomic::load_acquire(&_head._next) == &_tail;48}4950template <typename NodeType, typename AllocPolicy>51inline bool JfrConcurrentQueue<NodeType, AllocPolicy>::is_nonempty() const {52return !is_empty();53}5455template <typename NodeType, typename AllocPolicy>56void JfrConcurrentQueue<NodeType, AllocPolicy>::add(typename JfrConcurrentQueue<NodeType, AllocPolicy>::NodePtr node) {57_list->insert_tail(node, &_head, &_last, &_tail);58}5960template <typename NodeType, typename AllocPolicy>61typename JfrConcurrentQueue<NodeType, AllocPolicy>::NodePtr JfrConcurrentQueue<NodeType, AllocPolicy>::remove() {62return _list->remove(&_head, &_tail, &_last, false);63}6465template <typename NodeType, typename AllocPolicy>66template <typename Callback>67void JfrConcurrentQueue<NodeType, AllocPolicy>::iterate(Callback& cb) {68_list->iterate(&_head, &_tail, cb);69}7071template <typename NodeType, typename AllocPolicy>72inline JfrVersionSystem::Handle JfrConcurrentQueue<NodeType, AllocPolicy>::get_version_handle() {73return _version_system.get();74}7576template <typename NodeType, typename AllocPolicy>77bool JfrConcurrentQueue<NodeType, AllocPolicy>::in_list(const NodeType* node) const {78assert(node != NULL, "invariant");79return _list->in_list(node, const_cast<NodePtr>(&_head), &_tail);80}8182#endif // SHARE_JFR_UTILITIES_JFRCONCURRENTQUEUE_INLINE_HPP838485