2 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
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.
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.
18 #define ISC_COUNTER_H 1
24 /*! \file isc/counter.h
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.
38 #include <isc/mutex.h>
39 #include <isc/types.h>
48 isc_counter_create(isc_mem_t *mctx, int limit, isc_counter_t **counterp);
50 * Allocate and initialize a counter object.
54 isc_counter_increment(isc_counter_t *counter);
56 * Increment the counter.
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.)
64 isc_counter_used(isc_counter_t *counter);
66 * Return the current counter value.
70 isc_counter_setlimit(isc_counter_t *counter, int limit);
72 * Set the counter limit.
76 isc_counter_attach(isc_counter_t *source, isc_counter_t **targetp);
78 * Attach to a counter object, increasing its reference counter.
82 isc_counter_detach(isc_counter_t **counterp);
84 * Detach (and destroy if reference counter has dropped to zero)
90 #endif /* ISC_COUNTER_H */