1 /* $NetBSD: counter.h,v 1.5 2022/09/23 12:15:33 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #ifndef ISC_COUNTER_H 17 #define ISC_COUNTER_H 1 18 19 /***** 20 ***** Module Info 21 *****/ 22 23 /*! \file isc/counter.h 24 * 25 * \brief The isc_counter_t object is a simplified version of the 26 * isc_quota_t object; it tracks the consumption of limited 27 * resources, returning an error condition when the quota is 28 * exceeded. However, unlike isc_quota_t, attaching and detaching 29 * from a counter object does not increment or decrement the counter. 30 */ 31 32 /*** 33 *** Imports. 34 ***/ 35 36 #include <isc/lang.h> 37 #include <isc/mutex.h> 38 #include <isc/types.h> 39 40 /***** 41 ***** Types. 42 *****/ 43 44 ISC_LANG_BEGINDECLS 45 46 isc_result_t 47 isc_counter_create(isc_mem_t *mctx, int limit, isc_counter_t **counterp); 48 /*%< 49 * Allocate and initialize a counter object. 50 */ 51 52 isc_result_t 53 isc_counter_increment(isc_counter_t *counter); 54 /*%< 55 * Increment the counter. 56 * 57 * If the counter limit is nonzero and has been reached, then 58 * return ISC_R_QUOTA, otherwise ISC_R_SUCCESS. (The counter is 59 * incremented regardless of return value.) 60 */ 61 62 unsigned int 63 isc_counter_used(isc_counter_t *counter); 64 /*%< 65 * Return the current counter value. 66 */ 67 68 void 69 isc_counter_setlimit(isc_counter_t *counter, int limit); 70 /*%< 71 * Set the counter limit. 72 */ 73 74 void 75 isc_counter_attach(isc_counter_t *source, isc_counter_t **targetp); 76 /*%< 77 * Attach to a counter object, increasing its reference counter. 78 */ 79 80 void 81 isc_counter_detach(isc_counter_t **counterp); 82 /*%< 83 * Detach (and destroy if reference counter has dropped to zero) 84 * a counter object. 85 */ 86 87 ISC_LANG_ENDDECLS 88 89 #endif /* ISC_COUNTER_H */ 90