1/*
2 This file is part of Mtproto-proxy Library.
3
4 Mtproto-proxy Library is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 Mtproto-proxy Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mtproto-proxy Library. If not, see <http://www.gnu.org/licenses/>.
16
17 Copyright 2014 Telegram Messenger Inc
18 2014 Anton Maydell
19*/
20#pragma once
21
22#include <time.h>
23
24/* RDTSC */
25#if defined(__i386__)
26static __inline__ unsigned long long rdtsc(void) {
27 unsigned long long int x;
28 __asm__ volatile ("rdtsc" : "=A" (x));
29 return x;
30}
31#elif defined(__x86_64__)
32static __inline__ unsigned long long rdtsc(void) {
33 unsigned hi, lo;
34 __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
35 return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
36}
37#endif
38
39/* net-event.h */
40extern __thread int now;
41extern __thread double precise_now;
42extern __thread long long precise_now_rdtsc;
43double get_utime_monotonic (void);
44
45/* common/server-functions.h */
46double get_utime (int clock_id);
47extern long long precise_time; // (long long) (2^16 * precise unixtime)
48extern long long precise_time_rdtsc; // when precise_time was obtained
49long long get_precise_time (unsigned precision);
50
51/* ??? */
52double get_double_time (void);
53
54static inline void precise_sleep (int seconds, int nanoseconds) {
55 struct timespec t;
56 t.tv_sec = seconds;
57 t.tv_nsec = nanoseconds;
58 nanosleep (&t, NULL);
59}
60