1 /*-------------------------------------------------------------------------
2 * drawElements Utility Library
3 * ----------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief System clock.
22 *//*--------------------------------------------------------------------*/
28 #if (DE_OS == DE_OS_WIN32)
29 # define WIN32_LEAN_AND_MEAN
31 #elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_SYMBIAN) || (DE_OS == DE_OS_QNX)
33 #elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS)
34 # include <sys/time.h>
37 deUint64 deGetMicroseconds (void)
39 #if (DE_OS == DE_OS_WIN32)
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 */
47 if (count.QuadPart < MAXLONGLONG / 1000000)
49 DE_ASSERT(freq.QuadPart != 0);
50 return count.QuadPart * 1000000 / freq.QuadPart;
54 DE_ASSERT(freq.QuadPart >= 1000000);
55 return count.QuadPart / (freq.QuadPart / 1000000);
58 #elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_ANDROID) || (DE_OS == DE_OS_QNX)
59 struct timespec currTime;
60 clock_gettime(CLOCK_MONOTONIC, &currTime);
61 return (deUint64)currTime.tv_sec*1000000 + ((deUint64)currTime.tv_nsec/1000);
63 #elif (DE_OS == DE_OS_SYMBIAN)
64 struct timespec currTime;
65 /* Symbian supports only realtime clock for clock_gettime. */
66 /* \todo [2011-08-22 kalle] Proper Symbian-based implementation that is guaranteed to be monotonic. */
67 clock_gettime(CLOCK_REALTIME, &currTime);
68 return (deUint64)currTime.tv_sec*1000000 + ((deUint64)currTime.tv_nsec/1000);
70 #elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS)
71 struct timeval currTime;
72 gettimeofday(&currTime, DE_NULL);
73 return (deUint64)currTime.tv_sec*1000000 + (deUint64)currTime.tv_usec;
76 # error "Not implemented for target OS"
80 deUint64 deGetTime (void)
82 return (deUint64)time(DE_NULL);