Path: blob/master/runtime/gc_realtime/MetronomeAlarm.hpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2019 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#if !defined(METRONOME_ALARM_HPP_)23#define METRONOME_ALARM_HPP_ 12425/* @ddr_namespace: default */26/**27* @file28* @ingroup GC_Metronome29*/3031class MM_EnvironmentBase;32class MM_ProcessorInfo;33class MM_MetronomeAlarmThread;3435#include "omr.h"36#include "omrcfg.h"3738#include "Base.hpp"39#include "GCExtensionsBase.hpp"4041#if defined(WIN32)42#include "omrmutex.h"43#endif /* WIN32 */4445#if defined(LINUX)46#include <signal.h>47#endif /* LINUX */4849/**50* MM_Alarm51* A hi-resolution alarm that Metronome can use to gain control periodically52* This is an abstract class - you need to create a concrete alarm which is currently53* one of:54* MM_HRTAlarm (hi-resolution timer alarm - available on some Linux and AIX variants)55* MM_RTCAlarm (RTC device driver alarm - available on some Linux systems when run as root or sudo)56* MM_ITAlarm (interval timer alarm - default if nothing else available - not very high resolution)57* Use the factory service createAlarm() to create the right initial alarm for the system58*/59class MM_Alarm : protected MM_BaseVirtual60{61private:62protected:63MM_Alarm()64{65_typeId = __FUNCTION__;66}67virtual void tearDown(MM_EnvironmentBase *env);6869MM_GCExtensionsBase *_extensions;7071public:72virtual void kill(MM_EnvironmentBase *envModron);7374virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread)=0;75static MM_Alarm * factory(MM_EnvironmentBase *env, MM_OSInterface* osInterface);76virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize)=0;7778virtual void sleep()=0;79virtual void wakeUp(MM_MetronomeAlarmThread *) {};80};8182class MM_HRTAlarm : public MM_Alarm83{84public:85static MM_HRTAlarm * newInstance(MM_EnvironmentBase *env);8687MM_HRTAlarm() : MM_Alarm()88{89_typeId = __FUNCTION__;90}91virtual void sleep();92virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize);93virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread);94};9596class MM_RTCAlarm : public MM_Alarm97{98private:99#if defined(LINUX) && !defined(J9ZTPF)100IDATA RTCfd;101#endif /* defined(LINUX) && !defined(J9ZTPF) */102103public:104static MM_RTCAlarm * newInstance(MM_EnvironmentBase *env);105106MM_RTCAlarm() : MM_Alarm()107{108_typeId = __FUNCTION__;109}110virtual void sleep();111virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize);112virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread);113};114115class MM_ITAlarm : public MM_Alarm116{117private:118#if defined(WIN32)119HANDLE _hTimer;120#endif /* defined(WIN32) */121protected:122virtual void tearDown(MM_EnvironmentBase *env);123124public:125static MM_ITAlarm * newInstance(MM_EnvironmentBase *env);126127MM_ITAlarm() : MM_Alarm()128#if defined(WIN32)129, _hTimer(NULL)130#endif /* defined(WIN32) */131{132_typeId = __FUNCTION__;133}134virtual void sleep();135virtual void describe(OMRPortLibrary* port, char *buffer, I_32 bufferSize);136virtual bool initialize(MM_EnvironmentBase *env, MM_MetronomeAlarmThread* alarmThread);137static void alarm_handler(MM_MetronomeAlarmThread *);138virtual void wakeUp(MM_MetronomeAlarmThread *alarmThread) { alarm_handler(alarmThread); }139140#if defined(LINUX)141static MM_MetronomeAlarmThread *alarmHandlerArgument; /**< signal handlers do not get user-supplied args */142#endif /* LINUX */143};144145#endif /* METRONOME_ALARM_HPP_ */146147148