Skip to content

Commit

Permalink
fix: MiroKaku#40, KeQuerySystemTimePrecise not found in win7
Browse files Browse the repository at this point in the history
fix: MSVC 1939
  • Loading branch information
MiroKaku committed Apr 15, 2024
1 parent a74ab8c commit e63eaf9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions msvc/ucxxrt.test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
<ProjectName>ucxxrt.test</ProjectName>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<TargetVersion>Windows10</TargetVersion>
<TargetVersion>Windows7</TargetVersion>
<UseDebugLibraries>false</UseDebugLibraries>
<UseDebugLibraries Condition="'$(Configuration)'=='Debug'">true</UseDebugLibraries>
<PlatformToolset>WindowsKernelModeDriver10.0</PlatformToolset>
<ConfigurationType>Driver</ConfigurationType>
<DriverType>WDM</DriverType>
<DriverTargetPlatform>Universal</DriverTargetPlatform>
<DriverTargetPlatform>Desktop</DriverTargetPlatform>
<Driver_SpectreMitigation>Spectre</Driver_SpectreMitigation>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
Expand Down
2 changes: 2 additions & 0 deletions src/crt/stl/xlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <clocale>
#include <cstdlib>

//#pragma message(_CRT_STRINGIZE(_MSC_VER))

#if _MSC_VER >= 1936 // 17.6
#include "init_locks.hpp"
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/crt/stl/xmtx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

//#include <Windows.h>

#ifndef _RELIABILITY_CONTRACT
#define _RELIABILITY_CONTRACT
#endif

#pragma pack(push, _CRT_PACKING)
#pragma warning(push, 3)
#pragma push_macro("new")
Expand Down
10 changes: 7 additions & 3 deletions src/crt/stl/xnotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

//#include <Windows.h>

#if _MSC_VER < 1936 // 17.6
#define noexcept
#endif

constexpr int _Nitems = 20;

namespace {
Expand All @@ -33,7 +37,7 @@ void _Lock_at_thread_exit_mutex();
void _Unlock_at_thread_exit_mutex();

void __cdecl _Cnd_register_at_thread_exit(
_Cnd_t cnd, _Mtx_t mtx, int* p) { // register condition variable and mutex for cleanup at thread exit
_Cnd_t cnd, _Mtx_t mtx, int* p) noexcept { // register condition variable and mutex for cleanup at thread exit
// find block with available space
_At_thread_exit_block* block = &_Thread_exit_data;

Expand Down Expand Up @@ -62,7 +66,7 @@ void __cdecl _Cnd_register_at_thread_exit(
_Unlock_at_thread_exit_mutex();
}

void __cdecl _Cnd_unregister_at_thread_exit(_Mtx_t mtx) { // unregister condition variable/mutex for cleanup at thread exit
void __cdecl _Cnd_unregister_at_thread_exit(_Mtx_t mtx) noexcept { // unregister condition variable/mutex for cleanup at thread exit
// find condition variables waiting for this thread to exit
_At_thread_exit_block* block = &_Thread_exit_data;

Expand All @@ -80,7 +84,7 @@ void __cdecl _Cnd_unregister_at_thread_exit(_Mtx_t mtx) { // unregister conditio
_Unlock_at_thread_exit_mutex();
}

void __cdecl _Cnd_do_broadcast_at_thread_exit() { // notify condition variables waiting for this thread to exit
void __cdecl _Cnd_do_broadcast_at_thread_exit() noexcept { // notify condition variables waiting for this thread to exit
// find condition variables waiting for this thread to exit
_At_thread_exit_block* block = &_Thread_exit_data;
const unsigned int currentThreadId = _Thrd_id();
Expand Down
19 changes: 12 additions & 7 deletions src/crt/stl/xtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

// #include "awint.hpp"

#if _MSC_VER < 1936 // 17.6
#define noexcept
#endif

constexpr long _Nsec_per_sec = 1000000000L;
constexpr long _Nsec_per_msec = 1000000L;
constexpr int _Msec_per_sec = 1000;
Expand Down Expand Up @@ -48,27 +52,28 @@ constexpr long _Nsec100_per_sec = _Nsec_per_sec / 100;

_EXTERN_C

_CRTIMP2_PURE long long __cdecl _Xtime_get_ticks() { // get system time in 100-nanosecond intervals since the epoch
_CRTIMP2_PURE long long __cdecl _Xtime_get_ticks() noexcept { // get system time in 100-nanosecond intervals since the epoch
LARGE_INTEGER li;
KeQuerySystemTimePrecise(&li);
KeQuerySystemTime(&li);
//KeQuerySystemTimePrecise(&li);
return ((static_cast<long long>(li.HighPart)) << 32) + static_cast<long long>(li.LowPart) - _Epoch;
}

// Used by several src files, but not dllexported.
void _Timespec64_get_sys(_timespec64* xt) { // get system time with nanosecond resolution
void _Timespec64_get_sys(_timespec64* xt) noexcept { // get system time with nanosecond resolution
unsigned long long now = _Xtime_get_ticks();
xt->tv_sec = static_cast<__time64_t>(now / _Nsec100_per_sec);
xt->tv_nsec = static_cast<long>(now % _Nsec100_per_sec) * 100;
}

// convert time to milliseconds
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis2(const _timespec64* xt1, const _timespec64* xt2) {
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis2(const _timespec64* xt1, const _timespec64* xt2) noexcept {
_timespec64 diff = _timespec64_diff(xt1, xt2);
return static_cast<long>(diff.tv_sec * _Msec_per_sec + (diff.tv_nsec + _Nsec_per_msec - 1) / _Nsec_per_msec);
}

// TRANSITION, ABI: preserved for binary compatibility
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis(const _timespec64* xt) { // convert time to milliseconds
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis(const _timespec64* xt) noexcept { // convert time to milliseconds
_timespec64 now;
_Timespec64_get_sys(&now);
return _Xtime_diff_to_millis2(xt, &now);
Expand All @@ -86,13 +91,13 @@ _CRTIMP2_PURE int __cdecl xtime_get(_timespec64* xt, int type) { // get current
return type;
}

_CRTIMP2_PURE long long __cdecl _Query_perf_counter() { // get current value of performance counter
_CRTIMP2_PURE long long __cdecl _Query_perf_counter() noexcept { // get current value of performance counter
LARGE_INTEGER li;
KeQueryPerformanceCounter(&li); // always succeeds
return li.QuadPart;
}

_CRTIMP2_PURE long long __cdecl _Query_perf_frequency() { // get frequency of performance counter
_CRTIMP2_PURE long long __cdecl _Query_perf_frequency() noexcept { // get frequency of performance counter
static std::atomic<long long> freq_cached{ 0 };
long long freq = freq_cached.load(std::memory_order_relaxed);
if (freq == 0) {
Expand Down

0 comments on commit e63eaf9

Please sign in to comment.