Peter 5c1613d104 Add 'submodules/TelegramCore/' from commit '9561227540acef69894e6546395ab223a6233600'
git-subtree-dir: submodules/TelegramCore
git-subtree-mainline: 971273e8f8f49a47f14b251d2f35e3445a61fc3f
git-subtree-split: 9561227540acef69894e6546395ab223a6233600
2019-06-11 18:59:08 +01:00

30 lines
740 B
Objective-C

#import "MonotonicTime.h"
#include <sys/sysctl.h>
int64_t MonotonicGetBootTimestamp() {
struct timeval boottime;
int mib[2] = {CTL_KERN, KERN_BOOTTIME};
size_t size = sizeof(boottime);
int rc = sysctl(mib, 2, &boottime, &size, NULL, 0);
if (rc != 0) {
return 0;
}
return boottime.tv_sec * 1000000 + boottime.tv_usec;
}
int64_t MonotonicGetUptime() {
int64_t before_now;
int64_t after_now;
struct timeval now;
after_now = MonotonicGetBootTimestamp();
do {
before_now = after_now;
gettimeofday(&now, NULL);
after_now = MonotonicGetBootTimestamp();
} while (after_now != before_now);
return now.tv_sec * 1000000 + now.tv_usec - before_now;
}