Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/solaris/vm/threadCritical_solaris.cpp
32285 views
/*1* Copyright (c) 2001, 2010, 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#include "precompiled.hpp"25#include "runtime/thread.inline.hpp"26#include "runtime/threadCritical.hpp"2728// OS-includes here29#include <thread.h>30#include <synch.h>3132//33// See threadCritical.hpp for details of this class.34//35// For some reason, we don't do locking until the36// os::init() call completes. I'm not sure why this37// is, and have left it that way for now. This should38// be reviewed later.3940static mutex_t global_mut;41static thread_t global_mut_owner = -1;42static int global_mut_count = 0;43static bool initialized = false;4445ThreadCritical::ThreadCritical() {46if (initialized) {47thread_t owner = thr_self();48if (global_mut_owner != owner) {49if (os::Solaris::mutex_lock(&global_mut))50fatal(err_msg("ThreadCritical::ThreadCritical: mutex_lock failed (%s)",51strerror(errno)));52assert(global_mut_count == 0, "must have clean count");53assert(global_mut_owner == -1, "must have clean owner");54}55global_mut_owner = owner;56++global_mut_count;57} else {58assert (Threads::number_of_threads() == 0, "valid only during initialization");59}60}6162ThreadCritical::~ThreadCritical() {63if (initialized) {64assert(global_mut_owner == thr_self(), "must have correct owner");65assert(global_mut_count > 0, "must have correct count");66--global_mut_count;67if (global_mut_count == 0) {68global_mut_owner = -1;69if (os::Solaris::mutex_unlock(&global_mut))70fatal(err_msg("ThreadCritical::~ThreadCritical: mutex_unlock failed "71"(%s)", strerror(errno)));72}73} else {74assert (Threads::number_of_threads() == 0, "valid only during initialization");75}76}7778void ThreadCritical::initialize() {79// This method is called at the end of os::init(). Until80// then, we don't do real locking.81initialized = true;82}8384void ThreadCritical::release() {85}868788