threadCritical_aix.cpp revision 10049:73443d24e529
1238405Sjkim/* 2238405Sjkim * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 3238405Sjkim * Copyright (c) 2012, 2014 SAP SE. All rights reserved. 4238405Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5238405Sjkim * 6238405Sjkim * This code is free software; you can redistribute it and/or modify it 7238405Sjkim * under the terms of the GNU General Public License version 2 only, as 8238405Sjkim * published by the Free Software Foundation. 9238405Sjkim * 10238405Sjkim * This code is distributed in the hope that it will be useful, but WITHOUT 11238405Sjkim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12238405Sjkim * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13238405Sjkim * version 2 for more details (a copy is included in the LICENSE file that 14238405Sjkim * accompanied this code). 15238405Sjkim * 16238405Sjkim * You should have received a copy of the GNU General Public License version 17238405Sjkim * 2 along with this work; if not, write to the Free Software Foundation, 18238405Sjkim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19238405Sjkim * 20238405Sjkim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21238405Sjkim * or visit www.oracle.com if you need additional information or have any 22238405Sjkim * questions. 23238405Sjkim * 24238405Sjkim */ 25238405Sjkim 26238405Sjkim#include "precompiled.hpp" 27238405Sjkim#include "runtime/threadCritical.hpp" 28238405Sjkim#include "runtime/thread.inline.hpp" 29238405Sjkim 30238405Sjkim// put OS-includes here 31238405Sjkim# include <pthread.h> 32238405Sjkim 33238405Sjkim// 34238405Sjkim// See threadCritical.hpp for details of this class. 35238405Sjkim// 36238405Sjkim 37238405Sjkimstatic pthread_t tc_owner = 0; 38238405Sjkimstatic pthread_mutex_t tc_mutex = PTHREAD_MUTEX_INITIALIZER; 39238405Sjkimstatic int tc_count = 0; 40238405Sjkim 41238405Sjkimvoid ThreadCritical::initialize() { 42238405Sjkim} 43238405Sjkim 44238405Sjkimvoid ThreadCritical::release() { 45238405Sjkim} 46238405Sjkim 47238405SjkimThreadCritical::ThreadCritical() { 48238405Sjkim pthread_t self = pthread_self(); 49238405Sjkim if (self != tc_owner) { 50238405Sjkim int ret = pthread_mutex_lock(&tc_mutex); 51238405Sjkim guarantee(ret == 0, "fatal error with pthread_mutex_lock()"); 52238405Sjkim assert(tc_count == 0, "Lock acquired with illegal reentry count."); 53238405Sjkim tc_owner = self; 54238405Sjkim } 55238405Sjkim tc_count++; 56238405Sjkim} 57238405Sjkim 58238405SjkimThreadCritical::~ThreadCritical() { 59238405Sjkim assert(tc_owner == pthread_self(), "must have correct owner"); 60238405Sjkim assert(tc_count > 0, "must have correct count"); 61238405Sjkim 62238405Sjkim tc_count--; 63238405Sjkim if (tc_count == 0) { 64238405Sjkim tc_owner = 0; 65238405Sjkim int ret = pthread_mutex_unlock(&tc_mutex); 66238405Sjkim guarantee(ret == 0, "fatal error with pthread_mutex_unlock()"); 67238405Sjkim } 68238405Sjkim} 69238405Sjkim