Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/os/bsd/vm/threadCritical_bsd.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// put OS-includes here29# include <pthread.h>3031//32// See threadCritical.hpp for details of this class.33//3435static pthread_t tc_owner = 0;36static pthread_mutex_t tc_mutex = PTHREAD_MUTEX_INITIALIZER;37static int tc_count = 0;3839void ThreadCritical::initialize() {40}4142void ThreadCritical::release() {43}4445ThreadCritical::ThreadCritical() {46pthread_t self = pthread_self();47if (self != tc_owner) {48int ret = pthread_mutex_lock(&tc_mutex);49guarantee(ret == 0, "fatal error with pthread_mutex_lock()");50assert(tc_count == 0, "Lock acquired with illegal reentry count.");51tc_owner = self;52}53tc_count++;54}5556ThreadCritical::~ThreadCritical() {57assert(tc_owner == pthread_self(), "must have correct owner");58assert(tc_count > 0, "must have correct count");5960tc_count--;61if (tc_count == 0) {62tc_owner = 0;63int ret = pthread_mutex_unlock(&tc_mutex);64guarantee(ret == 0, "fatal error with pthread_mutex_unlock()");65}66}676869