Rizin
unix-like reverse engineering framework and cli tools
mytime.c
Go to the documentation of this file.
1 //
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 #include "private.h"
14 
15 #if !(defined(HAVE_CLOCK_GETTIME) && HAVE_DECL_CLOCK_MONOTONIC)
16 # include <sys/time.h>
17 #endif
18 
20 
23 
24 
28 static uint64_t
30 {
31  // NOTE: HAVE_DECL_CLOCK_MONOTONIC is always defined to 0 or 1.
32 #if defined(HAVE_CLOCK_GETTIME) && HAVE_DECL_CLOCK_MONOTONIC
33  // If CLOCK_MONOTONIC was available at compile time but for some
34  // reason isn't at runtime, fallback to CLOCK_REALTIME which
35  // according to POSIX is mandatory for all implementations.
36  static clockid_t clk_id = CLOCK_MONOTONIC;
37  struct timespec tv;
38  while (clock_gettime(clk_id, &tv))
39  clk_id = CLOCK_REALTIME;
40 
41  return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_nsec / 1000000);
42 #else
43  struct timeval tv;
44  gettimeofday(&tv, NULL);
45  return (uint64_t)tv.tv_sec * 1000 + (uint64_t)(tv.tv_usec / 1000);
46 #endif
47 }
48 
49 
50 extern void
52 {
54  return;
55 }
56 
57 
58 extern uint64_t
60 {
61  return mytime_now() - start_time;
62 }
63 
64 
65 extern void
67 {
69  return;
70 }
71 
72 
73 extern int
75 {
77  return -1;
78 
79  const uint64_t now = mytime_now();
80  if (now >= next_flush)
81  return 0;
82 
83  const uint64_t remaining = next_flush - now;
84  return remaining > INT_MAX ? INT_MAX : (int)remaining;
85 }
enum operation_mode opt_mode
Definition: coder.c:24
@ MODE_COMPRESS
Definition: coder.h:14
#define INT_MAX
Definition: cp-demangle.c:131
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval tv
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog gettimeofday
Definition: sflib.h:79
uint64_t mytime_get_elapsed(void)
Get the number of milliseconds since the operation started.
Definition: mytime.c:59
static uint64_t start_time
Definition: mytime.c:21
uint64_t opt_flush_timeout
Number of milliseconds to between LZMA_SYNC_FLUSHes.
Definition: mytime.c:19
static uint64_t mytime_now(void)
Get the current time as milliseconds.
Definition: mytime.c:29
int mytime_get_flush_timeout(void)
Get the number of milliseconds until the next flush.
Definition: mytime.c:74
void mytime_set_start_time(void)
Store the time when (de)compression was started.
Definition: mytime.c:51
void mytime_set_flush_time(void)
Store the time of when compressor was flushed.
Definition: mytime.c:66
static uint64_t next_flush
Definition: mytime.c:22
static int
Definition: sfsocketcall.h:114
unsigned long uint64_t
Definition: sftypes.h:28
Common includes, definitions, and prototypes.