simonis@6465: /* simonis@6465: * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. goetz@6515: * Copyright 2012, 2014 SAP AG. All rights reserved. simonis@6465: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. simonis@6465: * simonis@6465: * This code is free software; you can redistribute it and/or modify it simonis@6465: * under the terms of the GNU General Public License version 2 only, as simonis@6465: * published by the Free Software Foundation. simonis@6465: * simonis@6465: * This code is distributed in the hope that it will be useful, but WITHOUT simonis@6465: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or simonis@6465: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License simonis@6465: * version 2 for more details (a copy is included in the LICENSE file that simonis@6465: * accompanied this code). simonis@6465: * simonis@6465: * You should have received a copy of the GNU General Public License version simonis@6465: * 2 along with this work; if not, write to the Free Software Foundation, simonis@6465: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. simonis@6465: * simonis@6465: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA simonis@6465: * or visit www.oracle.com if you need additional information or have any simonis@6465: * questions. simonis@6465: * simonis@6465: */ simonis@6465: simonis@6465: #include "precompiled.hpp" simonis@6465: #include "runtime/threadCritical.hpp" goetz@6515: #include "runtime/thread.inline.hpp" simonis@6465: simonis@6465: // put OS-includes here simonis@6465: # include simonis@6465: simonis@6465: // simonis@6465: // See threadCritical.hpp for details of this class. simonis@6465: // simonis@6465: simonis@6465: static pthread_t tc_owner = 0; simonis@6465: static pthread_mutex_t tc_mutex = PTHREAD_MUTEX_INITIALIZER; simonis@6465: static int tc_count = 0; simonis@6465: simonis@6465: void ThreadCritical::initialize() { simonis@6465: } simonis@6465: simonis@6465: void ThreadCritical::release() { simonis@6465: } simonis@6465: simonis@6465: ThreadCritical::ThreadCritical() { simonis@6465: pthread_t self = pthread_self(); simonis@6465: if (self != tc_owner) { simonis@6465: int ret = pthread_mutex_lock(&tc_mutex); simonis@6465: guarantee(ret == 0, "fatal error with pthread_mutex_lock()"); simonis@6465: assert(tc_count == 0, "Lock acquired with illegal reentry count."); simonis@6465: tc_owner = self; simonis@6465: } simonis@6465: tc_count++; simonis@6465: } simonis@6465: simonis@6465: ThreadCritical::~ThreadCritical() { simonis@6465: assert(tc_owner == pthread_self(), "must have correct owner"); simonis@6465: assert(tc_count > 0, "must have correct count"); simonis@6465: simonis@6465: tc_count--; simonis@6465: if (tc_count == 0) { simonis@6465: tc_owner = 0; simonis@6465: int ret = pthread_mutex_unlock(&tc_mutex); simonis@6465: guarantee(ret == 0, "fatal error with pthread_mutex_unlock()"); simonis@6465: } simonis@6465: }