Ticket #8070: gettickcount64.patch

File gettickcount64.patch, 5.1 KB (added by raad@…, 4 years ago)

Determine GetTickCount64 support at runtime

  • include/boost/thread/win32/gettickcount64.hpp

     
     1#pragma once
     2
     3namespace boost
     4{
     5    namespace detail
     6    {
     7        namespace win32
     8        {
     9            typedef unsigned long long ticks_type;
     10            typedef ticks_type (__stdcall *gettickcount64fn)();
     11            typedef unsigned long (__stdcall *gettickcount32fn)();
     12            ticks_type GetTickCount64();
     13        }
     14    }
     15}
  • include/boost/thread/win32/thread_data.hpp

     
    1010#include <boost/thread/thread_time.hpp>
    1111#include <boost/thread/win32/thread_primitives.hpp>
    1212#include <boost/thread/win32/thread_heap_alloc.hpp>
     13#include <boost/thread/win32/gettickcount64.hpp>
    1314
    1415#include <boost/intrusive_ptr.hpp>
    1516#ifdef BOOST_THREAD_USES_CHRONO
  • include/boost/thread/win32/thread_primitives.hpp

     
    1818//#include <boost/detail/win/synchronization.hpp>
    1919#include <algorithm>
    2020
    21 #ifndef BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
    22 #if _WIN32_WINNT >= 0x0600 && ! defined _WIN32_WINNT_WS08
    23 #define BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
    24 #endif
    25 #endif
    26 
    2721#if defined( BOOST_USE_WINDOWS_H )
    2822# include <windows.h>
    2923
     
    3327    {
    3428        namespace win32
    3529        {
    36 #ifdef BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
    37             typedef unsigned long long ticks_type;
    38 #else
    39             typedef unsigned long ticks_type;
    40 #endif
    4130            typedef ULONG_PTR ulong_ptr;
    4231            typedef HANDLE handle;
    4332            unsigned const infinite=INFINITE;
     
    7463            using ::SleepEx;
    7564            using ::Sleep;
    7665            using ::QueueUserAPC;
    77             using ::GetTickCount;
    78 #ifdef BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
    79             using ::GetTickCount64;
    80 #else
    81             inline ticks_type GetTickCount64() { return GetTickCount(); }
    82 #endif
    8366        }
    8467    }
    8568}
     
    11497    {
    11598        namespace win32
    11699        {
    117 #ifdef BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
    118             typedef unsigned long long ticks_type;
    119 #else
    120             typedef unsigned long ticks_type;
    121 #endif
    122100# ifdef _WIN64
    123101            typedef unsigned __int64 ulong_ptr;
    124102# else
     
    157135                typedef void (__stdcall *queue_user_apc_callback_function)(ulong_ptr);
    158136                __declspec(dllimport) unsigned long __stdcall QueueUserAPC(queue_user_apc_callback_function,void*,ulong_ptr);
    159137
    160                 __declspec(dllimport) unsigned long __stdcall GetTickCount();
    161 # ifdef BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
    162                 __declspec(dllimport) ticks_type __stdcall GetTickCount64();
    163 # endif
    164138# ifndef UNDER_CE
    165139                __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId();
    166140                __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
     
    177151                using ::ResetEvent;
    178152# endif
    179153            }
    180 # ifndef BOOST_THREAD_WIN32_HAS_GET_TICK_COUNT_64
    181             inline ticks_type GetTickCount64() { return GetTickCount(); }
    182 # endif
    183154        }
    184155    }
    185156}
  • src/win32/gettickcount64.cpp

     
     1#include <boost/thread/win32/gettickcount64.hpp>
     2
     3#include <boost/thread/once.hpp>
     4
     5#ifdef BOOST_USE_WINDOWS_H
     6#include <Windows.h>
     7#else
     8extern "C"
     9{
     10    __declspec(dllimport) boost::detail::win32::gettickcount32fn __stdcall GetProcAddress(void *, const char *);
     11    __declspec(dllimport) void * __stdcall GetModuleHandleW(const wchar_t *);
     12}
     13#endif
     14
     15namespace boost
     16{
     17    namespace detail
     18    {
     19        namespace win32
     20        {
     21            namespace
     22            {
     23                gettickcount64fn gettickcount64 = NULL;
     24                gettickcount32fn gettickcount32 = NULL;
     25                ::boost::once_flag initfnonce = BOOST_ONCE_INIT;
     26
     27                void init_gettickcount64()
     28                {
     29                    gettickcount64 = reinterpret_cast<gettickcount64fn>(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "GetTickCount64"));
     30                    if(!gettickcount64)
     31                        gettickcount32 = reinterpret_cast<gettickcount32fn>(::GetProcAddress(::GetModuleHandleW(L"Kernel32.dll"), "GetTickCount"));
     32                }
     33            }
     34
     35            ticks_type GetTickCount64()
     36            {
     37                ::boost::call_once(&init_gettickcount64, initfnonce);
     38                return gettickcount64 ? gettickcount64() : static_cast<ticks_type>(gettickcount32());
     39            }
     40        }
     41    }
     42}