Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_realtime/MetronomeAlarm.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2019 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
#if !defined(METRONOME_ALARM_HPP_)
24
#define METRONOME_ALARM_HPP_ 1
25
26
/* @ddr_namespace: default */
27
/**
28
* @file
29
* @ingroup GC_Metronome
30
*/
31
32
class MM_EnvironmentBase;
33
class MM_ProcessorInfo;
34
class MM_MetronomeAlarmThread;
35
36
#include "omr.h"
37
#include "omrcfg.h"
38
39
#include "Base.hpp"
40
#include "GCExtensionsBase.hpp"
41
42
#if defined(WIN32)
43
#include "omrmutex.h"
44
#endif /* WIN32 */
45
46
#if defined(LINUX)
47
#include <signal.h>
48
#endif /* LINUX */
49
50
/**
51
* MM_Alarm
52
* A hi-resolution alarm that Metronome can use to gain control periodically
53
* This is an abstract class - you need to create a concrete alarm which is currently
54
* one of:
55
* MM_HRTAlarm (hi-resolution timer alarm - available on some Linux and AIX variants)
56
* MM_RTCAlarm (RTC device driver alarm - available on some Linux systems when run as root or sudo)
57
* MM_ITAlarm (interval timer alarm - default if nothing else available - not very high resolution)
58
* Use the factory service createAlarm() to create the right initial alarm for the system
59
*/
60
class MM_Alarm : protected MM_BaseVirtual
61
{
62
private:
63
protected:
64
MM_Alarm()
65
{
66
_typeId = __FUNCTION__;
67
}
68
virtual void tearDown(MM_EnvironmentBase *env);
69
70
MM_GCExtensionsBase *_extensions;
71
72
public:
73
virtual void kill(MM_EnvironmentBase *envModron);
74
75
virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread)=0;
76
static MM_Alarm * factory(MM_EnvironmentBase *env, MM_OSInterface* osInterface);
77
virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize)=0;
78
79
virtual void sleep()=0;
80
virtual void wakeUp(MM_MetronomeAlarmThread *) {};
81
};
82
83
class MM_HRTAlarm : public MM_Alarm
84
{
85
public:
86
static MM_HRTAlarm * newInstance(MM_EnvironmentBase *env);
87
88
MM_HRTAlarm() : MM_Alarm()
89
{
90
_typeId = __FUNCTION__;
91
}
92
virtual void sleep();
93
virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize);
94
virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread);
95
};
96
97
class MM_RTCAlarm : public MM_Alarm
98
{
99
private:
100
#if defined(LINUX) && !defined(J9ZTPF)
101
IDATA RTCfd;
102
#endif /* defined(LINUX) && !defined(J9ZTPF) */
103
104
public:
105
static MM_RTCAlarm * newInstance(MM_EnvironmentBase *env);
106
107
MM_RTCAlarm() : MM_Alarm()
108
{
109
_typeId = __FUNCTION__;
110
}
111
virtual void sleep();
112
virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize);
113
virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread);
114
};
115
116
class MM_ITAlarm : public MM_Alarm
117
{
118
private:
119
#if defined(WIN32)
120
HANDLE _hTimer;
121
#endif /* defined(WIN32) */
122
protected:
123
virtual void tearDown(MM_EnvironmentBase *env);
124
125
public:
126
static MM_ITAlarm * newInstance(MM_EnvironmentBase *env);
127
128
MM_ITAlarm() : MM_Alarm()
129
#if defined(WIN32)
130
, _hTimer(NULL)
131
#endif /* defined(WIN32) */
132
{
133
_typeId = __FUNCTION__;
134
}
135
virtual void sleep();
136
virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize);
137
virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread);
138
static void alarm_handler(MM_MetronomeAlarmThread *);
139
virtual void wakeUp(MM_MetronomeAlarmThread *alarmThread) { alarm_handler(alarmThread); }
140
141
#if defined(LINUX)
142
static MM_MetronomeAlarmThread *alarmHandlerArgument; /**< signal handlers do not get user-supplied args */
143
#endif /* LINUX */
144
};
145
146
#endif /* METRONOME_ALARM_HPP_ */
147
148