All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
target/Linux-x86_64/include/aerospike/as_timer.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 #pragma once
23 
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdbool.h>
27 #include <stdint.h>
28 
29 /*****************************************************************************
30  * TYPES
31  *****************************************************************************/
32 
33 struct as_timer_s;
34 /**
35  * The interface which all timer should implement.
36  */
37 typedef struct as_timer_hooks_s {
38  /**
39  * The destroy should free resources associated with the timer's source.
40  * The destroy should not free the timer itself.
41  */
42  int (* destroy)(struct as_timer_s *);
43  bool (* timedout)(const struct as_timer_s *);
44  uint64_t (* timeslice)(const struct as_timer_s *);
46 
47 /**
48  * Timer handle
49  */
50 typedef struct as_timer_s {
51  bool is_malloc;
52  void * source;
53  const as_timer_hooks * hooks;
54 } as_timer;
55 
56 /*****************************************************************************
57  * FUNCTIONS
58  *****************************************************************************/
59 
60 /**
61  * Initialize a stack allocated timer
62  */
63 as_timer * as_timer_init(as_timer * timer, void * source, const as_timer_hooks * hooks);
64 
65 /**
66  * Heap allocate and initialize a timer
67  */
68 as_timer * as_timer_new(void * source, const as_timer_hooks * hooks);
69 
70 
71 static inline void * as_timer_source(const as_timer * tt) {
72  return (tt ? tt->source : NULL);
73 }
74 
75 /**
76  * Release resources associated with the timer.
77  * Calls timer->destroy. If success and if this is a heap allocated
78  * timer, then it will be freed.
79  */
80 int as_timer_destroy(as_timer * timer);
81 
82 /**
83  * true if timer has timedout
84  */
85 bool as_timer_timedout(const as_timer * timer);
86 
87 /**
88  * returns timeslice assigned for this timer
89  */
90 uint64_t as_timer_timeslice(const as_timer * timer);
bool as_timer_timedout(const as_timer *timer)
static void * as_timer_source(const as_timer *tt)
uint64_t as_timer_timeslice(const as_timer *timer)
int as_timer_destroy(as_timer *timer)
as_timer * as_timer_new(void *source, const as_timer_hooks *hooks)
as_timer * as_timer_init(as_timer *timer, void *source, const as_timer_hooks *hooks)