Path: blob/master/runtime/compiler/infra/J9Monitor.hpp
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#ifndef J9_MONITOR_INCL23#define J9_MONITOR_INCL2425#ifndef J9_MONITOR_CONNECTOR26#define J9_MONITOR_CONNECTOR27namespace J9 { class Monitor; }28namespace J9 { typedef J9::Monitor MonitorConnector; }29#endif3031#include "env/TRMemory.hpp"32#include "infra/Link.hpp"3334struct J9PortLibrary;35struct J9ThreadMonitor;36struct J9JavaVM;37struct J9VMThread;38namespace TR { class MonitorTable; }39namespace TR { class Monitor; }40namespace J9 { class MonitorTable; }4142namespace J943{4445class Monitor : public TR_Link0<TR::Monitor>46{47public:4849static TR::Monitor *create(char *name);50static void destroy(TR::Monitor *monitor);5152void enter();5354int32_t try_enter();5556int32_t exit();5758void destroy();5960void wait();6162intptr_t wait_timed(int64_t millis, int32_t nanos);6364void notify();6566void notifyAll();6768int32_t num_waiting();6970int32_t owned_by_self(); // returns 1 if current thread owns the monitor, 0 otherwise7172// Dangerous: do not use this routine, except for thread exit73void *getVMMonitor() { return (void*)_monitor; }7475private:7677friend class J9::MonitorTable;7879void *operator new(size_t size, void *p) { return p; }80void operator delete(void *p);81void operator delete(void *p, void *) {}8283bool init(char *name);8485bool initFromVMMutex(void *mutex);8687J9ThreadMonitor *_monitor;88};8990}9192#endif939495