-add macros for msvc/gcc portable int64 suffix/LARGE_INTEGER handling

-add C_ASSERT (compile-time asserts)

svn path=/trunk/; revision=13446
This commit is contained in:
Gunnar Dalsnes 2005-02-06 19:04:00 +00:00
parent bc7bba6f78
commit fa4b4f314a

View file

@ -32,18 +32,45 @@
# define PROBE_ALIGNMENT(_s) TYPE_ALIGNMENT(DWORD) # define PROBE_ALIGNMENT(_s) TYPE_ALIGNMENT(DWORD)
#endif #endif
#if defined(_MSC_VER)
#define Const64(a) (a##i64)
static __inline LARGE_INTEGER MK_LARGE_INTEGER(__int64 i)
{
LARGE_INTEGER li;
li.QuadPart = i;
return li;
}
#define INIT_LARGE_INTEGER(a) {{(ULONG)a, (LONG)(a>>32)}}
#elif defined (__GNUC__)
#define Const64(a) (a##LL)
#define MK_LARGE_INTEGER(a) ((LARGE_INTEGER)(LONGLONG)(a))
#define INIT_LARGE_INTEGER(a) MK_LARGE_INTEGER(Const64(a))
#endif
#define LargeInteger0 MK_LARGE_INTEGER(0)
/* Compile time asserts */
#define C_ASSERT(e) do{extern char __C_ASSERT__[(e)?1:-1]; (void)__C_ASSERT__;}while(0)
/* Helpers for easy conversion to system time units (100ns) */ /* Helpers for easy conversion to system time units (100ns) */
#define ABSOLUTE_TIME(wait) (wait) #define ABSOLUTE_TIME(wait) (wait)
#define RELATIVE_TIME(wait) (-(wait)) #define RELATIVE_TIME(wait) (-(wait))
#define NANOS_TO_100NS(nanos) (((LONGLONG)(nanos)) / 100L) #define NANOS_TO_100NS(nanos) (((LONGLONG)(nanos)) / 100)
#define MICROS_TO_100NS(micros) (((LONGLONG)(micros)) * NANOS_TO_100NS(1000L)) #define MICROS_TO_100NS(micros) (((LONGLONG)(micros)) * NANOS_TO_100NS(1000))
#define MILLIS_TO_100NS(milli) (((LONGLONG)(milli)) * MICROS_TO_100NS(1000L)) #define MILLIS_TO_100NS(milli) (((LONGLONG)(milli)) * MICROS_TO_100NS(1000))
#define SECONDS_TO_100NS(seconds) (((LONGLONG)(seconds)) * MILLIS_TO_100NS(1000L)) #define SECONDS_TO_100NS(seconds) (((LONGLONG)(seconds)) * MILLIS_TO_100NS(1000))
#define MINUTES_TO_100NS(minutes) (((LONGLONG)(minutes)) * SECONDS_TO_100NS(60))
#define HOURS_TO_100NS(hours) (((LONGLONG)(hours)) * MINUTES_TO_100NS(60))
/* Helpers for enumarating lists */ /* Helpers for enumarating lists */
#define LIST_FOR_EACH(entry, head) \ #define LIST_FOR_EACH(entry, head) \
for(entry = (head)->Flink; entry != (head); entry = entry->Flink) for((entry) = (head)->Flink; (entry) != (head); (entry) = (entry)->Flink)
/* /*
Safe version which saves pointer to the next entry so the current ptr->field entry Safe version which saves pointer to the next entry so the current ptr->field entry