Path: blob/master/runtime/compiler/infra/J9Monitor.cpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception20*******************************************************************************/2122#include "infra/J9Monitor.hpp"2324#include "j9.h"25#include "j9cfg.h"26#include "j9port.h"27#include "j9thread.h"28#include "infra/Monitor.hpp"29#include "infra/MonitorTable.hpp"3031TR::MonitorTable *OMR::MonitorTable::_instance = 0;3233TR::Monitor *34J9::Monitor::create(char *name)35{36return TR::MonitorTable::get()->create(name);37}3839void40J9::Monitor::destroy(TR::Monitor *monitor)41{42TR::MonitorTable::get()->removeAndDestroy(monitor);43}4445bool46J9::Monitor::init(char *name)47{48setNext(0);49if (j9thread_monitor_init_with_name((J9ThreadMonitor**)&_monitor, 0, name))50return false;51else52return true;53}5455bool56J9::Monitor::initFromVMMutex(void *mutex)57{58_monitor = (J9ThreadMonitor*)mutex;59return true;60}6162void63J9::Monitor::enter()64{65TR_ASSERT(_monitor != TR::MonitorTable::get()->getClassTableMutex()->getVMMonitor(), "Use TR::ClassTableCriticalSection instead");66j9thread_monitor_enter(_monitor);67}6869void70J9::Monitor::destroy()71{72j9thread_monitor_destroy(_monitor);73}7475void76J9::Monitor::wait()77{78j9thread_monitor_wait(_monitor);79}8081intptr_t82J9::Monitor::wait_timed(int64_t millis, int32_t nanos)83{84return j9thread_monitor_wait_timed(_monitor, millis, nanos);85}8687void88J9::Monitor::notify()89{90j9thread_monitor_notify(_monitor);91}9293void94J9::Monitor::notifyAll()95{96j9thread_monitor_notify_all(_monitor);97}9899int32_t100J9::Monitor::exit()101{102return (int32_t)j9thread_monitor_exit(_monitor);103}104105int32_t106J9::Monitor::try_enter()107{108return (int32_t)j9thread_monitor_try_enter(_monitor);109}110111int32_t112J9::Monitor::num_waiting()113{114return (int32_t)j9thread_monitor_num_waiting(_monitor);115}116117int32_t118J9::Monitor::owned_by_self()119{120return (int32_t)j9thread_monitor_owned_by_self(_monitor);121}122123124