Lines Matching refs:quota
1 /* $NetBSD: quota.c,v 1.11 2025/05/21 14:48:05 christos Exp $ */
21 #include <isc/quota.h>
29 isc_quota_init(isc_quota_t *quota, unsigned int max) {
30 atomic_init("a->max, max);
31 atomic_init("a->used, 0);
32 atomic_init("a->soft, 0);
33 cds_wfcq_init("a->jobs.head, "a->jobs.tail);
34 ISC_LINK_INIT(quota, link);
35 quota->magic = QUOTA_MAGIC;
39 isc_quota_soft(isc_quota_t *quota, unsigned int soft) {
40 REQUIRE(VALID_QUOTA(quota));
41 atomic_store_relaxed("a->soft, soft);
45 isc_quota_max(isc_quota_t *quota, unsigned int max) {
46 REQUIRE(VALID_QUOTA(quota));
47 atomic_store_relaxed("a->max, max);
51 isc_quota_getmax(isc_quota_t *quota) {
52 REQUIRE(VALID_QUOTA(quota));
53 return atomic_load_relaxed("a->max);
57 isc_quota_getsoft(isc_quota_t *quota) {
58 REQUIRE(VALID_QUOTA(quota));
59 return atomic_load_relaxed("a->soft);
63 isc_quota_getused(isc_quota_t *quota) {
64 REQUIRE(VALID_QUOTA(quota));
65 return atomic_load_acquire("a->used);
69 isc_quota_release(isc_quota_t *quota) {
77 node = cds_wfcq_dequeue_blocking("a->jobs.head, "a->jobs.tail);
79 uint_fast32_t used = atomic_fetch_sub_acq_rel("a->used, 1);
83 * If this was the last quota released and in the meantime a
85 * to run, otherwise it could get stuck there until a new quota
89 !cds_wfcq_empty("a->jobs.head, "a->jobs.tail))
91 atomic_fetch_add_acq_rel("a->used, 1);
103 isc_quota_acquire_cb(isc_quota_t *quota, isc_job_t *job, isc_job_cb cb,
105 REQUIRE(VALID_QUOTA(quota));
108 uint_fast32_t used = atomic_fetch_add_acq_rel("a->used, 1);
109 uint_fast32_t max = atomic_load_relaxed("a->max);
111 (void)atomic_fetch_sub_acq_rel("a->used, 1);
121 cds_wfcq_enqueue("a->jobs.head, "a->jobs.tail,
126 * quotas might have been released, and if no quota is
128 * have a chance to get running until a new quota is
130 * quota->used again, if it's 0 then simulate a quota
136 "a->used, &(uint_fast32_t){ 0 }, 1))
138 isc_quota_release(quota);
144 uint_fast32_t soft = atomic_load_relaxed("a->soft);
153 isc_quota_destroy(isc_quota_t *quota) {
154 REQUIRE(VALID_QUOTA(quota));
155 quota->magic = 0;
157 INSIST(atomic_load_acquire("a->used) == 0);
158 INSIST(cds_wfcq_empty("a->jobs.head, "a->jobs.tail));
160 cds_wfcq_destroy("a->jobs.head, "a->jobs.tail);