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