ReactOS 0.4.16-dev-852-gcfcc8d8
clock.cpp File Reference
#include <corecrt_internal_time.h>
#include <sys/timeb.h>
#include <sys/types.h>
Include dependency graph for clock.cpp:

Go to the source code of this file.

Functions

static long long scale_count (long long count)
 
int __cdecl __acrt_initialize_clock ()
 
 _CRT_LINKER_FORCE_INCLUDE (__acrt_clock_initializer)
 
clock_t __cdecl clock ()
 

Variables

static long long source_frequency
 
static long long start_count
 

Function Documentation

◆ __acrt_initialize_clock()

int __cdecl __acrt_initialize_clock ( )

Definition at line 46 of file clock.cpp.

47{
48 LARGE_INTEGER local_frequency;
49 LARGE_INTEGER local_start_count;
50 if (!QueryPerformanceFrequency(&local_frequency) ||
51 !QueryPerformanceCounter(&local_start_count) ||
52 local_frequency.QuadPart == 0)
53 {
55 start_count = -1;
56 return 0;
57 }
58
59 source_frequency = local_frequency.QuadPart;
60 start_count = local_start_count.QuadPart;
61
62 return 0;
63}
static long long start_count
Definition: clock.cpp:18
static long long source_frequency
Definition: clock.cpp:17
BOOL WINAPI QueryPerformanceFrequency(OUT PLARGE_INTEGER lpFrequency)
Definition: perfcnt.c:45
BOOL WINAPI QueryPerformanceCounter(OUT PLARGE_INTEGER lpPerformanceCount)
Definition: perfcnt.c:23
LONGLONG QuadPart
Definition: typedefs.h:114

◆ _CRT_LINKER_FORCE_INCLUDE()

_CRT_LINKER_FORCE_INCLUDE ( __acrt_clock_initializer  )

◆ clock()

clock_t __cdecl clock ( void  )

Definition at line 74 of file clock.cpp.

75{
76 if (start_count == -1)
77 return -1;
78
79 LARGE_INTEGER current_count;
80 if (!QueryPerformanceCounter(&current_count))
81 return -1;
82
83 long long const result = current_count.QuadPart - start_count;
84 if (result < 0)
85 return -1;
86
87 long long const scaled_result = scale_count(result);
88
89 // Per C11 7.27.2.1 ("The clock function")/3, "If the processor time used...
90 // cannot be represented, the function returns the value (clock_t)(-1)."
91 if (scaled_result > LONG_MAX)
92 return -1;
93
94 return static_cast<clock_t>(scaled_result);
95}
static long long scale_count(long long count)
Definition: clock.cpp:25
__kernel_clock_t clock_t
Definition: linux.h:257
GLuint64EXT * result
Definition: glext.h:11304
#define LONG_MAX
Definition: intsafe.h:154

Referenced by BaseRendererImpl_SetSyncSource(), CKsClockForwarder_Constructor(), DMUSIC_CreateReferenceClockImpl(), get_time(), IDirectMusic8Impl_SetExternalMasterClock(), LIBXML_ATTR_FORMAT(), master_clock_create(), MediaStreamFilterImpl_GetSyncSource(), MediaStreamFilterImpl_SetSyncSource(), midi_IDirectMusicPort_GetLatencyClock(), QualityControlRender_SetClock(), startTimer(), SynthPortImpl_IDirectMusicPort_GetLatencyClock(), test_query_interface(), and test_wmreader_interfaces().

◆ scale_count()

static long long scale_count ( long long  count)
static

Definition at line 25 of file clock.cpp.

26{
27 // Convert the count to seconds and multiply this by the destination frequency:
28 long long scaled_count = (count / source_frequency) * CLOCKS_PER_SEC;
29
30 // To reduce error introduced by scaling using integer division, separately
31 // handle the remainder from the above division by multiplying the left-over
32 // counter by the destination frequency, then diviting by the input frequency:
34
35 scaled_count += (count * CLOCKS_PER_SEC) / source_frequency;
36
37 return scaled_count;
38}
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define CLOCKS_PER_SEC
Definition: time.h:81

Referenced by clock().

Variable Documentation

◆ source_frequency

long long source_frequency
static

Definition at line 17 of file clock.cpp.

Referenced by __acrt_initialize_clock(), and scale_count().

◆ start_count

long long start_count
static

Definition at line 18 of file clock.cpp.

Referenced by __acrt_initialize_clock(), clock(), and TEXT_SkipChars().