rabbitmq-c
C AMQP Client library for RabbitMQ
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
amqp_timer.h
1 /* vim:set ft=c ts=2 sw=2 sts=2 et cindent: */
2 /*
3  * Copyright 2013 Alan Antonuk
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef AMQP_TIMER_H
24 #define AMQP_TIMER_H
25 
26 #include <stdint.h>
27 
28 #ifdef _WIN32
29 # ifndef WIN32_LEAN_AND_MEAN
30 # define WIN32_LEAN_AND_MEAN
31 # endif
32 # include <Winsock2.h>
33 #else
34 # include <sys/time.h>
35 #endif
36 
37 #define AMQP_NS_PER_S 1000000000
38 #define AMQP_NS_PER_US 1000
39 
40 #define AMQP_INIT_TIMER(structure) { \
41  structure.current_timestamp = 0; \
42  structure.timeout_timestamp = 0; \
43 }
44 
45 typedef struct amqp_timer_t_ {
46  uint64_t current_timestamp;
47  uint64_t timeout_timestamp;
48  uint64_t ns_until_next_timeout;
49  struct timeval tv;
50 } amqp_timer_t;
51 
52 /* Gets a monotonic timestamp in ns */
53 uint64_t
54 amqp_get_monotonic_timestamp(void);
55 
56 /* Prepare timeout value and modify timer state based on timer state. */
57 int
58 amqp_timer_update(amqp_timer_t *timer, struct timeval *timeout);
59 
60 #endif /* AMQP_TIMER_H */
61