00001 /* 00002 * Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC") 00003 * 00004 * Permission to use, copy, modify, and/or distribute this software for any 00005 * purpose with or without fee is hereby granted, provided that the above 00006 * copyright notice and this permission notice appear in all copies. 00007 * 00008 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00009 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00010 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00011 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00012 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00013 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00014 * PERFORMANCE OF THIS SOFTWARE. 00015 */ 00016 00017 #ifndef ISC_COUNTER_H 00018 #define ISC_COUNTER_H 1 00019 00020 /***** 00021 ***** Module Info 00022 *****/ 00023 00024 /*! \file isc/counter.h 00025 * 00026 * \brief The isc_counter_t object is a simplified version of the 00027 * isc_quota_t object; it tracks the consumption of limited 00028 * resources, returning an error condition when the quota is 00029 * exceeded. However, unlike isc_quota_t, attaching and detaching 00030 * from a counter object does not increment or decrement the counter. 00031 */ 00032 00033 /*** 00034 *** Imports. 00035 ***/ 00036 00037 #include <isc/lang.h> 00038 #include <isc/mutex.h> 00039 #include <isc/types.h> 00040 00041 /***** 00042 ***** Types. 00043 *****/ 00044 00045 ISC_LANG_BEGINDECLS 00046 00047 isc_result_t 00048 isc_counter_create(isc_mem_t *mctx, int limit, isc_counter_t **counterp); 00049 /*%< 00050 * Allocate and initialize a counter object. 00051 */ 00052 00053 isc_result_t 00054 isc_counter_increment(isc_counter_t *counter); 00055 /*%< 00056 * Increment the counter. 00057 * 00058 * If the counter limit is nonzero and has been reached, then 00059 * return ISC_R_QUOTA, otherwise ISC_R_SUCCESS. (The counter is 00060 * incremented regardless of return value.) 00061 */ 00062 00063 unsigned int 00064 isc_counter_used(isc_counter_t *counter); 00065 /*%< 00066 * Return the current counter value. 00067 */ 00068 00069 void 00070 isc_counter_setlimit(isc_counter_t *counter, int limit); 00071 /*%< 00072 * Set the counter limit. 00073 */ 00074 00075 void 00076 isc_counter_attach(isc_counter_t *source, isc_counter_t **targetp); 00077 /*%< 00078 * Attach to a counter object, increasing its reference counter. 00079 */ 00080 00081 void 00082 isc_counter_detach(isc_counter_t **counterp); 00083 /*%< 00084 * Detach (and destroy if reference counter has dropped to zero) 00085 * a counter object. 00086 */ 00087 00088 ISC_LANG_ENDDECLS 00089 00090 #endif /* ISC_COUNTER_H */