Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/infra/J9Monitor.cpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
#include "infra/J9Monitor.hpp"
24
25
#include "j9.h"
26
#include "j9cfg.h"
27
#include "j9port.h"
28
#include "j9thread.h"
29
#include "infra/Monitor.hpp"
30
#include "infra/MonitorTable.hpp"
31
32
TR::MonitorTable *OMR::MonitorTable::_instance = 0;
33
34
TR::Monitor *
35
J9::Monitor::create(char *name)
36
{
37
return TR::MonitorTable::get()->create(name);
38
}
39
40
void
41
J9::Monitor::destroy(TR::Monitor *monitor)
42
{
43
TR::MonitorTable::get()->removeAndDestroy(monitor);
44
}
45
46
bool
47
J9::Monitor::init(char *name)
48
{
49
setNext(0);
50
if (j9thread_monitor_init_with_name((J9ThreadMonitor**)&_monitor, 0, name))
51
return false;
52
else
53
return true;
54
}
55
56
bool
57
J9::Monitor::initFromVMMutex(void *mutex)
58
{
59
_monitor = (J9ThreadMonitor*)mutex;
60
return true;
61
}
62
63
void
64
J9::Monitor::enter()
65
{
66
TR_ASSERT(_monitor != TR::MonitorTable::get()->getClassTableMutex()->getVMMonitor(), "Use TR::ClassTableCriticalSection instead");
67
j9thread_monitor_enter(_monitor);
68
}
69
70
void
71
J9::Monitor::destroy()
72
{
73
j9thread_monitor_destroy(_monitor);
74
}
75
76
void
77
J9::Monitor::wait()
78
{
79
j9thread_monitor_wait(_monitor);
80
}
81
82
intptr_t
83
J9::Monitor::wait_timed(int64_t millis, int32_t nanos)
84
{
85
return j9thread_monitor_wait_timed(_monitor, millis, nanos);
86
}
87
88
void
89
J9::Monitor::notify()
90
{
91
j9thread_monitor_notify(_monitor);
92
}
93
94
void
95
J9::Monitor::notifyAll()
96
{
97
j9thread_monitor_notify_all(_monitor);
98
}
99
100
int32_t
101
J9::Monitor::exit()
102
{
103
return (int32_t)j9thread_monitor_exit(_monitor);
104
}
105
106
int32_t
107
J9::Monitor::try_enter()
108
{
109
return (int32_t)j9thread_monitor_try_enter(_monitor);
110
}
111
112
int32_t
113
J9::Monitor::num_waiting()
114
{
115
return (int32_t)j9thread_monitor_num_waiting(_monitor);
116
}
117
118
int32_t
119
J9::Monitor::owned_by_self()
120
{
121
return (int32_t)j9thread_monitor_owned_by_self(_monitor);
122
}
123
124