8000 Merge pull request #3929 from libgit2/vmg/time · libgit2/libgit2@89c332e · GitHub
[go: up one dir, main page]

Skip to content

Commit 89c332e

Browse files
author
Edward Thomson
authored
Merge pull request #3929 from libgit2/vmg/time
time: Export `git_time_monotonic`
2 parents bba704a + 2749ff4 commit 89c332e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/git2/sys/time.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_git_time_h__
8+
#define INCLUDE_git_time_h__
9+
10+
#include "git2/common.h"
11+
12+
GIT_BEGIN_DECL
13+
14+
/**
15+
* Return a monotonic time value, useful for measuring running time
16+
* and setting up timeouts.
17+
*
18+
* The returned value is an arbitrary point in time -- it can only be
19+
* used when comparing it to another `git_time_monotonic` call.
20+
*
21+
* The time is returned in seconds, with a decimal fraction that differs
22+
* on accuracy based on the underlying system, but should be least
23+
* accurate to Nanoseconds.
24+
*
25+
* This function cannot fail.
26+
*/
27+
GIT_EXTERN(double) git_time_monotonic(void);
28+
29+
GIT_END_DECL
30+
#endif
31+

src/util.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ int git__utf8_iterate(const uint8_t *str, int str_len, int32_t *dst)
783783
return length;
784784
}
785785

786+
double git_time_monotonic(void)
787+
{
788+
return git__timer();
789+
}
790+
786791
#ifdef GIT_WIN32
787792
int git__getenv(git_buf *out, const char *name)
788793
{

0 commit comments

Comments
 (0)
0