def InitializeWinNowFunction(plat):
  """Sets a monotonic clock for windows platforms.

    Args:
      plat: Platform that is being run on.
  """
  global _CLOCK  # pylint: disable=global-statement
  global _NOW_FUNCTION  # pylint: disable=global-statement

  if IsQPCUsable():
    _CLOCK = _WIN_HIRES
    qpc_return = ctypes.c_int64()
    qpc_frequency = ctypes.c_int64()
    ctypes.windll.Kernel32.QueryPerformanceFrequency(
        ctypes.byref(qpc_frequency))
    qpc_frequency = float(qpc_frequency.value)
    qpc = ctypes.windll.Kernel32.QueryPerformanceCounter

    def WinNowFunctionImpl():
      qpc(ctypes.byref(qpc_return))
      return qpc_return.value / qpc_frequency

  else:
    _CLOCK = _WIN_LORES
    kernel32 = (ctypes.cdll.kernel32
                if plat.startswith(_PLATFORMS['cygwin'])
                else ctypes.windll.kernel32)
    get_tick_count_64 = getattr(kernel32, 'GetTickCount64', None)

    # Windows Vista or newer
    if get_tick_count_64:
      get_tick_count_64.restype = ctypes.c_ulonglong

      def WinNowFunctionImpl():
        return get_tick_count_64() / 1000.0

    else:  # Pre Vista.
      get_tick_count = kernel32.GetTickCount
      get_tick_count.restype = ctypes.c_uint32
      get_tick_count_lock = threading.Lock()

      def WinNowFunctionImpl():
        global GET_TICK_COUNT_LAST_NOW  # pylint: disable=global-statement
        global GET_TICK_COUNT_WRAPAROUNDS  # pylint: disable=global-statement
        with get_tick_count_lock:
          current_sample = get_tick_count()
          if current_sample < GET_TICK_COUNT_LAST_NOW:
            GET_TICK_COUNT_WRAPAROUNDS += 1
          GET_TICK_COUNT_LAST_NOW = current_sample
          final_ms = GET_TICK_COUNT_WRAPAROUNDS << 32
          final_ms += GET_TICK_COUNT_LAST_NOW
          return final_ms / 1000.0

  _NOW_FUNCTION = WinNowFunctionImpl