1 /*	$NetBSD: counter.h,v 1.1.1.2 2014/12/10 03:34:44 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2014  Internet Systems Consortium, Inc. ("ISC")
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef ISC_COUNTER_H
20 #define ISC_COUNTER_H 1
21 
22 /*****
23  ***** Module Info
24  *****/
25 
26 /*! \file isc/counter.h
27  *
28  * \brief The isc_counter_t object is a simplified version of the
29  * isc_quota_t object; it tracks the consumption of limited
30  * resources, returning an error condition when the quota is
31  * exceeded.  However, unlike isc_quota_t, attaching and detaching
32  * from a counter object does not increment or decrement the counter.
33  */
34 
35 /***
36  *** Imports.
37  ***/
38 
39 #include <isc/lang.h>
40 #include <isc/mutex.h>
41 #include <isc/types.h>
42 
43 /*****
44  ***** Types.
45  *****/
46 
47 ISC_LANG_BEGINDECLS
48 
49 isc_result_t
50 isc_counter_create(isc_mem_t *mctx, int limit, isc_counter_t **counterp);
51 /*%<
52  * Allocate and initialize a counter object.
53  */
54 
55 isc_result_t
56 isc_counter_increment(isc_counter_t *counter);
57 /*%<
58  * Increment the counter.
59  *
60  * If the counter limit is nonzero and has been reached, then
61  * return ISC_R_QUOTA, otherwise ISC_R_SUCCESS. (The counter is
62  * incremented regardless of return value.)
63  */
64 
65 unsigned int
66 isc_counter_used(isc_counter_t *counter);
67 /*%<
68  * Return the current counter value.
69  */
70 
71 void
72 isc_counter_setlimit(isc_counter_t *counter, int limit);
73 /*%<
74  * Set the counter limit.
75  */
76 
77 void
78 isc_counter_attach(isc_counter_t *source, isc_counter_t **targetp);
79 /*%<
80  * Attach to a counter object, increasing its reference counter.
81  */
82 
83 void
84 isc_counter_detach(isc_counter_t **counterp);
85 /*%<
86  * Detach (and destroy if reference counter has dropped to zero)
87  * a counter object.
88  */
89 
90 ISC_LANG_ENDDECLS
91 
92 #endif /* ISC_COUNTER_H */
93