Skip to content

[Android] Fix the issue that Environment.TickCount returns wrong value… #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions mono/utils/mono-time.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ mono_100ns_datetime (void)

#include <time.h>

/* a made up uptime of 300 seconds */
#define MADEUP_BOOT_TIME (300 * MTICKS_PER_SEC)

static gint64
get_boot_time (void)
{
Expand Down Expand Up @@ -121,21 +124,28 @@ get_boot_time (void)
fclose (uptime);
}
#endif
/* a made up uptime of 300 seconds */
return (gint64)300 * MTICKS_PER_SEC;
return (gint64)MADEUP_BOOT_TIME;
}

/* Returns the number of milliseconds from boot time: this should be monotonic */
gint64
mono_msec_boottime (void)
{
#if defined(ANDROID)
struct timespec ts;
if (clock_gettime (CLOCK_MONOTONIC, &ts) != 0) {
return (gint64)MADEUP_BOOT_TIME;
}
return (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
#else
static gint64 boot_time = 0;
gint64 now;
if (!boot_time)
boot_time = get_boot_time ();
now = mono_100ns_datetime ();
/*printf ("now: %llu (boot: %llu) ticks: %llu\n", (gint64)now, (gint64)boot_time, (gint64)(now - boot_time));*/
return (now - boot_time)/10000;
#endif
}

/* Returns the number of 100ns ticks from unspecified time: this should be monotonic */
Expand Down