I focus on Windows XP, and I need a function like GetTickCount64 that does not overflow.
I could not find a suitable solution that would be correct and thread safe, so I tried to roll my own.
Here is what I came up with:
ULONGLONG MyGetTickCount64(void) { static volatile DWORD dwHigh = 0; static volatile DWORD dwLastLow = 0; DWORD dwTickCount; dwTickCount = GetTickCount(); if(dwTickCount < (DWORD)InterlockedExchange(&dwLastLow, dwTickCount)) { InterlockedIncrement(&dwHigh); } return (ULONGLONG)dwTickCount | (ULONGLONG)dwHigh << 32; }
Is it really thread safe?
Thread safety is difficult to verify for correctness, so Iโm not sure if it is really correct in all cases.
source share