1 /*------------------------------------------------------------------------- 2 * drawElements Utility Library 3 * ---------------------------- 4 * 5 * Copyright 2014 The Android Open Source Project 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 * 19 *//*! 20 * \file 21 * \brief System clock. 22 *//*--------------------------------------------------------------------*/ 23 24 #include "deClock.h" 25 26 #include <time.h> 27 28 #if (DE_OS == DE_OS_WIN32) 29 # define WIN32_LEAN_AND_MEAN 30 # include <windows.h> 31 #elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_SYMBIAN) 32 # include <time.h> 33 #elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS) 34 # include <sys/time.h> 35 #endif 36 deGetMicroseconds(void)37deUint64 deGetMicroseconds (void) 38 { 39 #if (DE_OS == DE_OS_WIN32) 40 LARGE_INTEGER freq; 41 LARGE_INTEGER count; 42 QueryPerformanceCounter(&count); 43 QueryPerformanceFrequency(&freq); 44 DE_ASSERT(freq.LowPart != 0 || freq.HighPart != 0); 45 /* \todo [2010-03-26 kalle] consider adding a 32bit-friendly implementation */ 46 DE_ASSERT(freq.QuadPart >= 1000000); 47 return count.QuadPart / (freq.QuadPart / 1000000); 48 49 #elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_ANDROID) 50 struct timespec currTime; 51 clock_gettime(CLOCK_MONOTONIC, &currTime); 52 return (deUint64)currTime.tv_sec*1000000 + ((deUint64)currTime.tv_nsec/1000); 53 54 #elif (DE_OS == DE_OS_SYMBIAN) 55 struct timespec currTime; 56 /* Symbian supports only realtime clock for clock_gettime. */ 57 /* \todo [2011-08-22 kalle] Proper Symbian-based implementation that is guaranteed to be monotonic. */ 58 clock_gettime(CLOCK_REALTIME, &currTime); 59 return (deUint64)currTime.tv_sec*1000000 + ((deUint64)currTime.tv_nsec/1000); 60 61 #elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS) 62 struct timeval currTime; 63 gettimeofday(&currTime, DE_NULL); 64 return (deUint64)currTime.tv_sec*1000000 + (deUint64)currTime.tv_usec; 65 66 #else 67 # error "Not implemented for target OS" 68 #endif 69 } 70 deGetTime(void)71deUint64 deGetTime (void) 72 { 73 return (deUint64)time(DE_NULL); 74 } 75