Get Absolute Time
Àý´ëÀû ¼ø¹æÇ⠽ð£ÀÚ¿ø ¾ò±â ¶
Contents1.1. ½ÃÀÛÇϱâÀü¿¡ ¶ÇÁ·Î±×·¡¹ÖÀ» ÇÏ´Ù°¡ º¸¸é Àý´ëÀûÀ¸·Î ¼ø¹æÇâÀ¸·Î¸¸ Áõ°¡ÇÏ´Â ½Ã°£ÀÚ¿øÀÌ ÇÊ¿äÇÒ¶§°¡ ¸¹½À´Ï´Ù.
ƯÁ¤ ½Ã°£ ±¸°£ÀÇ ¼Ò¿ä½Ã°£À» ÃøÁ¤ÇÑ´Ù´ø°¡ ƯÁ¤ Áֱ⸶´Ù ¾î¶² ½ÇÇàÀ» ±¸ÇöÇÏ·Á°í ÇÒ¶§ ÀϹÝÀûÀÎ ½Ã°èÀÚ¿øÀÇ °æ¿ì ½Ã°£µ¿±â°¡ Áß°£¿¡ ÀϾ¸é ½Ã°£ÀÌ ¿ª¹æÇ⠶Ǵ ¸¹Àº ½Ã°£À» °Ç³Ê¶Ù´Â »óÅ°¡ ¹ß»ýÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ·²¶§ ÃæºÐÈ÷ °í·ÁµÇÁö ¾ÊÀ¸¸é ÇÁ·Î±×·¥Àº ÀǵµµÇÁö ¾ÊÀº µ¿ÀÛÀ» ÀÏÀ¸Å°±â ¸Å¿ì ½±½À´Ï´Ù. ¿©±â¼´Â ÃÖ´ëÇÑ ¸¹Àº Platform¿¡¼ µ¿ÀÛ°¡´ÉÇÑ Àý´ëÀû ¼ø¹æÇ⠽ð£ÀÚ¿ø¿¡ ´ëÇÑ ±¸ÇöÀ» ´Ù·ç°íÀÚ ÇÕ´Ï´Ù. Àý´ëÀû ¼ø¹æÇ⠽ð£ÀÚ¿øÀÇ ±¸Çö¿¡ ÇʼöÀûÀÎ ¿ä±¸»çÇ×Àº ´ÙÀ½°ú °°½À´Ï´Ù.
1.2. Windows ¿¡¼ÀÇ ±¸Çö ¶#define hwport_uintmax_t ULONGLONG int __hwport_get_absolute_time_msec(hwport_uintmax_t *s_msec_ptr) { LARGE_INTEGER s_performance_frequency; LARGE_INTEGER s_performance_count; if(QueryPerformanceFrequency((LARGE_INTEGER *)(&s_performance_frequency)) != TRUE) { return(-1); } if(s_performance_frequency.QuadPart == ((LONGLONG)0)) { return(-1); } if(QueryPerformanceCounter((LARGE_INTEGER *)(&s_performance_count)) != TRUE) { return(-1); } *s_msec_ptr = ((((hwport_uintmax_t)s_performance_count.QuadPart) * ((hwport_uintmax_t)1000u)) / ((hwport_uintmax_t)s_performance_frequency.QuadPart)); return(0); } 1.3. OS X ¿¡¼ÀÇ ±¸Çö (Mach kernel ±â¹Ý) ¶# include <mach/mach_time.h> #define hwport_uintmax_t unsigned long long int __hwport_get_absolute_time_msec(hwport_uintmax_t *s_msec_ptr) { mach_timebase_info_data_t s_timebase; /* mach kernel */ mach_timebase_info(&s_timebase); if(s_timebase.denom == 0) { return(-1); } *s_msec_ptr = (((hwport_uintmax_t)mach_absolute_time()) * ((hwport_uintmax_t)s_timebase.numer)) / (((hwport_uintmax_t)s_timebase.denom) * ((hwport_uintmax_t)1000000)); return(0); } 1.4. Linux(¶Ç´Â Android) ¿¡¼ÀÇ ±¸Çö (librt.so ¸¦ Á÷Á¢ ¸µÅ©ÇÏÁö ¾Ê°í SystemCallÀ» Á÷Á¢ »ç¿ëÇÏ´Â ¹æ¹ý) ¶/* need define _GNU_SOURCE */ # include <unistd.h> # include <sys/syscall.h> # ifndef CLOCK_MONOTONIC # warning "Old glibc (< 2.3.4) does not provide this constant. We use syscall directly so this definition is safe." # define CLOCK_MONOTONIC 1 # endif # if !defined(SYS_clock_gettime) # define SYS_clock_gettime __NR_clock_gettime # endif #define hwport_uintmax_t unsigned long long int __hwport_get_absolute_time_msec(hwport_uintmax_t *s_msec_ptr) { struct timespec s_timespec; /* libc has incredibly messy way of doing this, typically requiring -lrt. We just skip all this mess */ if(syscall(SYS_clock_gettime /* __NR_clock_gettime */, (int)CLOCK_MONOTONIC, (void *)(&s_timespec)) != 0) { return(-1); } *s_msec_ptr = (((hwport_uintmax_t)s_timespec.tv_sec) * ((hwport_uintmax_t)1000u)) + (((hwport_uintmax_t)s_timespec.tv_nsec) / ((hwport_uintmax_t)1000000u)); return(0); } 1.5. Unix/BSD/Linux °è¿¿¡¼ÀÇ ±¸Çö (SUv2 ¹× POSIX.1-2001 À» ¸¸Á·Çϴ ȯ°æ, rt library¸¦ ¸µÅ©ÇØ¾ß ÇÏ´Â °æ¿ì°¡ ÇÊ¿äÇÒ¼ö ÀÖÀ½) ¶#define hwport_uintmax_t unsigned long long int __hwport_get_absolute_time_msec(hwport_uintmax_t *s_msec_ptr) { struct timespec s_timespec; /* maybe requiring -lrt */ /* SUSv2, POSIX.1-2001 */ if(clock_gettime((clockid_t)CLOCK_MONOTONIC, (struct timespec *)(&s_timespec)) != 0) { return(-1); } *s_msec_ptr = (((hwport_uintmax_t)s_timespec.tv_sec) * ((hwport_uintmax_t)1000u)) + (((hwport_uintmax_t)s_timespec.tv_nsec) / ((hwport_uintmax_t)1000000u)); return(0); } 1.6. ±âŸȯ°æ¿¡¼ÀÇ ±¸Çö ¶
|