Lines Matching defs:counter
15 #include <isc/counter.h>
35 isc_counter_t *counter;
39 counter = isc_mem_get(mctx, sizeof(*counter));
40 if (counter == NULL)
43 result = isc_mutex_init(&counter->lock);
45 isc_mem_put(mctx, counter, sizeof(*counter));
49 counter->mctx = NULL;
50 isc_mem_attach(mctx, &counter->mctx);
52 counter->references = 1;
53 counter->limit = limit;
54 counter->used = 0;
56 counter->magic = COUNTER_MAGIC;
57 *counterp = counter;
62 isc_counter_increment(isc_counter_t *counter) {
65 LOCK(&counter->lock);
66 counter->used++;
67 if (counter->limit != 0 && counter->used >= counter->limit)
69 UNLOCK(&counter->lock);
75 isc_counter_used(isc_counter_t *counter) {
76 REQUIRE(VALID_COUNTER(counter));
78 return (counter->used);
82 isc_counter_setlimit(isc_counter_t *counter, int limit) {
83 REQUIRE(VALID_COUNTER(counter));
85 LOCK(&counter->lock);
86 counter->limit = limit;
87 UNLOCK(&counter->lock);
104 destroy(isc_counter_t *counter) {
105 counter->magic = 0;
106 isc_mutex_destroy(&counter->lock);
107 isc_mem_putanddetach(&counter->mctx, counter, sizeof(*counter));
112 isc_counter_t *counter;
116 counter = *counterp;
117 REQUIRE(VALID_COUNTER(counter));
121 LOCK(&counter->lock);
122 INSIST(counter->references > 0);
123 counter->references--;
124 if (counter->references == 0)
126 UNLOCK(&counter->lock);
129 destroy(counter);