diff options
author | Stiver <stiver.mail@gmail.com> | 2014-03-04 15:13:11 +0100 |
---|---|---|
committer | Stiver <stiver.mail@gmail.com> | 2014-03-04 15:13:11 +0100 |
commit | e2d0f5d9c38561d67f23754c00addb4a3547efb2 (patch) | |
tree | 1832f16037c086b48266b8566aecc61f45f4e5f1 /timer/native | |
download | fernflower-e2d0f5d9c38561d67f23754c00addb4a3547efb2.tar fernflower-e2d0f5d9c38561d67f23754c00addb4a3547efb2.tar.gz fernflower-e2d0f5d9c38561d67f23754c00addb4a3547efb2.tar.lz fernflower-e2d0f5d9c38561d67f23754c00addb4a3547efb2.tar.xz fernflower-e2d0f5d9c38561d67f23754c00addb4a3547efb2.zip |
initial commit
Diffstat (limited to 'timer/native')
-rw-r--r-- | timer/native/com_vladium_utils_timing_HRTimer.c | 71 | ||||
-rw-r--r-- | timer/native/com_vladium_utils_timing_HRTimer.h | 22 |
2 files changed, 93 insertions, 0 deletions
diff --git a/timer/native/com_vladium_utils_timing_HRTimer.c b/timer/native/com_vladium_utils_timing_HRTimer.c new file mode 100644 index 0000000..647837d --- /dev/null +++ b/timer/native/com_vladium_utils_timing_HRTimer.c @@ -0,0 +1,71 @@ +/* ------------------------------------------------------------------------- */ +/* + * A win32 implementation of JNI methods in com.vladium.utils.timing.HRTimer + * class. The author compiled it using Microsoft Visual C++ but the code + * should be easy to use with any compiler for win32 platform. + * + * For simplicity, this implementaion assumes JNI 1.2+ and omits error handling. + * + * (C) 2002, Vladimir Roubtsov [vroubtsov@illinoisalumni.org] + */ +/* ------------------------------------------------------------------------- */ + +#if !defined NDEBUG +#include <stdio.h> +#endif // NDEBUG + +#include <windows.h> + +#include "com_vladium_utils_timing_HRTimer.h" + +// scale factor for converting a performancce counter reading into milliseconds: +static jdouble s_scaleFactor; + +/* ------------------------------------------------------------------------- */ + +/* + * This method was added in JNI 1.2. It is executed once before any other + * methods are called and is ostensibly for negotiating JNI spec versions, but + * can also be conveniently used for initializing variables that will not + * change throughout the lifetime of this process. + */ +JNIEXPORT jint JNICALL +JNI_OnLoad (JavaVM * vm, void * reserved) +{ + LARGE_INTEGER counterFrequency; + + QueryPerformanceFrequency (& counterFrequency); + + // NOTE: counterFrequency will be zero for a machine that does not have + // support for a high-resolution counter. This is only likely for very + // old hardware but for a robust implementation you should handle this + // case. + +#if !defined NDEBUG + printf ("PCFrequency called: %I64d\n", counterFrequency.QuadPart); +#endif + + s_scaleFactor = counterFrequency.QuadPart / 1000.0; + + + return JNI_VERSION_1_2; +} +/* ......................................................................... */ + +/* + * Class: com_vladium_utils_timing_HRTimer + * Method: getTime + * Signature: ()D + */ +JNIEXPORT jdouble JNICALL +Java_com_vladium_utils_timing_HRTimer_getTime (JNIEnv * e, jclass cls) +{ + LARGE_INTEGER counterReading; + + QueryPerformanceCounter (& counterReading); + + return counterReading.QuadPart / s_scaleFactor; +} + +/* ------------------------------------------------------------------------- */ +/* end of file */ diff --git a/timer/native/com_vladium_utils_timing_HRTimer.h b/timer/native/com_vladium_utils_timing_HRTimer.h new file mode 100644 index 0000000..357db0d --- /dev/null +++ b/timer/native/com_vladium_utils_timing_HRTimer.h @@ -0,0 +1,22 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include <jni.h> +/* Header for class com_vladium_utils_timing_HRTimer */ + +#ifndef _Included_com_vladium_utils_timing_HRTimer +#define _Included_com_vladium_utils_timing_HRTimer +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Class: com_vladium_utils_timing_HRTimer + * Method: getTime + * Signature: ()D + */ +JNIEXPORT jdouble JNICALL +Java_com_vladium_utils_timing_HRTimer_getTime (JNIEnv *, jclass); + +#ifdef __cplusplus +} +#endif +#endif |