#ifndef CP_SRDTSC_H
#define CP_SRDTSC_H

#include "srdtsc.h"

#ifdef __cplusplus
extern "C" {
#endif

#if !defined(NO_LEOH_READTSC) /* определение cp_read_tsc */
#define cp_read_tsc NULL
#elif defined _M_ARM
static DWORD CPCAPI cp_read_tsc(ULONGLONG *pTSC, LPVOID lpArg)
{
    LARGE_INTEGER i;
    UNUSED(lpArg);
    if (!QueryPerformanceCounter(&i))
	return (DWORD)NTE_FAIL;
    *pTSC = i.QuadPart;
    return S_OK;
}
#elif defined(UNIX) && defined(IOS)
// for mach_absolute_time
# include <mach/mach_time.h>
static DWORD cp_read_tsc(ULONGLONG * pTSC, LPVOID lpArg)
{
    UNUSED(lpArg);
    *pTSC = mach_absolute_time();
    return S_OK;
}
#elif defined(ANDROID) || ( defined(LINUX) && defined(PROCESSOR_TYPE) && (PROCESSOR_TYPE == PROC_TYPE_ARM || PROCESSOR_TYPE == PROC_TYPE_ARM64 || PROCESSOR_TYPE == PROC_TYPE_MIPS32) )
// for clock_gettime
# include <time.h>
static inline DWORD cp_read_tsc(ULONGLONG *pTSC, LPVOID lpArg)
{
    struct timespec t;

    UNUSED(lpArg);
    clock_gettime(CLOCK_REALTIME, &t);
    *pTSC = t.tv_nsec;
    return S_OK;
}
#else
# error No TSC source defined
#endif /* конец определения cp_read_tsc */

#ifdef __cplusplus
}
#endif

#endif /* CP_SRDTSC_H */
