quota.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 2000, 2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: quota.h,v 1.16 2007/06/19 23:47:18 tbox Exp $ */
00019 
00020 #ifndef ISC_QUOTA_H
00021 #define ISC_QUOTA_H 1
00022 
00023 /*****
00024  ***** Module Info
00025  *****/
00026 
00027 /*! \file isc/quota.h
00028  *
00029  * \brief The isc_quota_t object is a simple helper object for implementing
00030  * quotas on things like the number of simultaneous connections to
00031  * a server.  It keeps track of the amount of quota in use, and
00032  * encapsulates the locking necessary to allow multiple tasks to
00033  * share a quota.
00034  */
00035 
00036 /***
00037  *** Imports.
00038  ***/
00039 
00040 #include <isc/lang.h>
00041 #include <isc/mutex.h>
00042 #include <isc/types.h>
00043 
00044 /*****
00045  ***** Types.
00046  *****/
00047 
00048 ISC_LANG_BEGINDECLS
00049 
00050 /*% isc_quota structure */
00051 struct isc_quota {
00052         isc_mutex_t     lock; /*%< Locked by lock. */
00053         int             max;
00054         int             used;
00055         int             soft;
00056 };
00057 
00058 isc_result_t
00059 isc_quota_init(isc_quota_t *quota, int max);
00060 /*%<
00061  * Initialize a quota object.
00062  *
00063  * Returns:
00064  *      ISC_R_SUCCESS
00065  *      Other error     Lock creation failed.
00066  */
00067 
00068 void
00069 isc_quota_destroy(isc_quota_t *quota);
00070 /*%<
00071  * Destroy a quota object.
00072  */
00073 
00074 void
00075 isc_quota_soft(isc_quota_t *quota, int soft);
00076 /*%<
00077  * Set a soft quota.
00078  */
00079 
00080 void
00081 isc_quota_max(isc_quota_t *quota, int max);
00082 /*%<
00083  * Re-set a maximum quota.
00084  */
00085 
00086 isc_result_t
00087 isc_quota_reserve(isc_quota_t *quota);
00088 /*%<
00089  * Attempt to reserve one unit of 'quota'.
00090  *
00091  * Returns:
00092  * \li  #ISC_R_SUCCESS          Success
00093  * \li  #ISC_R_SOFTQUOTA        Success soft quota reached
00094  * \li  #ISC_R_QUOTA            Quota is full
00095  */
00096 
00097 void
00098 isc_quota_release(isc_quota_t *quota);
00099 /*%<
00100  * Release one unit of quota.
00101  */
00102 
00103 isc_result_t
00104 isc_quota_attach(isc_quota_t *quota, isc_quota_t **p);
00105 /*%<
00106  * Like isc_quota_reserve, and also attaches '*p' to the
00107  * quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA).
00108  */
00109 
00110 void
00111 isc_quota_detach(isc_quota_t **p);
00112 /*%<
00113  * Like isc_quota_release, and also detaches '*p' from the
00114  * quota.
00115  */
00116 
00117 ISC_LANG_ENDDECLS
00118 
00119 #endif /* ISC_QUOTA_H */

Generated on Tue Apr 28 17:41:04 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha