summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_inline_private.h
blob: 846081dd8873f76c93792654b1796d9af1e5a1bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* EINA - EFL data type library
 * Copyright (C) 2013  Cedric Bail
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifndef EINA_INLINE_PRIVATE_H_
# define EINA_INLINE_PRIVATE_H_

# include <time.h>
# include <sys/time.h>

typedef struct timespec Eina_Nano_Time;

static inline int
_eina_time_get(Eina_Nano_Time *tp)
{
# if defined(CLOCK_PROCESS_CPUTIME_ID)
   if (!clock_gettime(CLOCK_PROCESS_CPUTIME_ID, tp))
     return 0;
# endif
# if defined(CLOCK_PROF)
   if (!clock_gettime(CLOCK_PROF, tp))
     return 0;
# endif
# if defined(CLOCK_REALTIME)
   if (!clock_gettime(CLOCK_REALTIME, tp))
     return 0;
# endif

/* FIXME: Have a look if and how we can support CLOCK_MONOTONIC */

   struct timeval tv;

   if (gettimeofday(&tv, NULL))
     return -1;

   tp->tv_sec = tv.tv_sec;
   tp->tv_nsec = tv.tv_usec * 1000L;

   return 0;
}

static inline long int
_eina_time_convert(Eina_Nano_Time *tp)
{
  long int r;

  r = tp->tv_sec * 1000000000 + tp->tv_nsec;

  return r;
}

static inline long int
_eina_time_delta(Eina_Nano_Time *start, Eina_Nano_Time *end)
{
  long int r;

  r = (end->tv_sec - start->tv_sec) * 1000000000 +
    end->tv_nsec - start->tv_nsec;

  return r;
}

#endif