4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: quota.h,v 1.16 2007/06/19 23:47:18 tbox Exp */
31 * \brief The isc_quota_t object is a simple helper object for implementing
32 * quotas on things like the number of simultaneous connections to
33 * a server. It keeps track of the amount of quota in use, and
34 * encapsulates the locking necessary to allow multiple tasks to
43 #include <isc/mutex.h>
44 #include <isc/types.h>
52 /*% isc_quota structure */
54 isc_mutex_t lock
; /*%< Locked by lock. */
61 isc_quota_init(isc_quota_t
*quota
, int max
);
63 * Initialize a quota object.
67 * Other error Lock creation failed.
71 isc_quota_destroy(isc_quota_t
*quota
);
73 * Destroy a quota object.
77 isc_quota_soft(isc_quota_t
*quota
, int soft
);
83 isc_quota_max(isc_quota_t
*quota
, int max
);
85 * Re-set a maximum quota.
89 isc_quota_reserve(isc_quota_t
*quota
);
91 * Attempt to reserve one unit of 'quota'.
94 * \li #ISC_R_SUCCESS Success
95 * \li #ISC_R_SOFTQUOTA Success soft quota reached
96 * \li #ISC_R_QUOTA Quota is full
100 isc_quota_release(isc_quota_t
*quota
);
102 * Release one unit of quota.
106 isc_quota_attach(isc_quota_t
*quota
, isc_quota_t
**p
);
108 * Like isc_quota_reserve, and also attaches '*p' to the
109 * quota if successful (ISC_R_SUCCESS or ISC_R_SOFTQUOTA).
113 isc_quota_detach(isc_quota_t
**p
);
115 * Like isc_quota_release, and also detaches '*p' from the
121 #endif /* ISC_QUOTA_H */