Lines Matching refs:template

113 #define template_lock(template)		lck_mtx_lock(&(template)->lt_lock)
114 #define template_unlock(template) lck_mtx_unlock(&(template)->lt_lock)
210 ledger_template_t template;
212 template = (ledger_template_t)kalloc(sizeof (*template));
213 if (template == NULL)
216 template->lt_name = name;
217 template->lt_refs = 1;
218 template->lt_cnt = 0;
219 template->lt_table_size = 1;
220 template->lt_inuse = 0;
221 lck_mtx_init(&template->lt_lock, &ledger_lck_grp, LCK_ATTR_NULL);
223 template->lt_entries = (struct entry_template *)
224 kalloc(sizeof (struct entry_template) * template->lt_table_size);
225 if (template->lt_entries == NULL) {
226 kfree(template, sizeof (*template));
227 template = NULL;
230 return (template);
234 ledger_template_dereference(ledger_template_t template)
236 template_lock(template);
237 template->lt_refs--;
238 template_unlock(template);
240 if (template->lt_refs == 0)
241 kfree(template, sizeof (*template));
245 * Add a new entry to the list of entries in a ledger template. There is
251 ledger_entry_add(ledger_template_t template, const char *key,
260 template_lock(template);
263 if (template->lt_cnt == template->lt_table_size) {
268 old_cnt = template->lt_table_size;
272 template_unlock(template);
275 memcpy(new_entries, template->lt_entries, old_sz);
277 template->lt_table_size = old_cnt * 2;
279 old_entries = template->lt_entries;
281 TEMPLATE_INUSE(s, template);
282 template->lt_entries = new_entries;
283 TEMPLATE_IDLE(s, template);
288 et = &template->lt_entries[template->lt_cnt];
295 idx = template->lt_cnt++;
296 template_unlock(template);
319 ledger_key_lookup(ledger_template_t template, const char *key)
323 template_lock(template);
324 for (idx = 0; idx < template->lt_cnt; idx++)
325 if (template->lt_entries[idx].et_key &&
326 (strcmp(key, template->lt_entries[idx].et_key) == 0))
329 if (idx >= template->lt_cnt)
331 template_unlock(template);
337 * Create a new ledger based on the specified template. As part of the
339 * The size of the table is based on the size of the template at the time
340 * the ledger is created. If additional entries are added to the template
344 ledger_instantiate(ledger_template_t template, int entry_type)
354 ledger->l_template = template;
358 template_lock(template);
359 template->lt_refs++;
360 ledger->l_size = template->lt_cnt;
361 template_unlock(template);
366 ledger_template_dereference(template);
371 template_lock(template);
372 assert(ledger->l_size <= template->lt_cnt);
375 struct entry_template *et = &template->lt_entries[i];
382 * If template has a callback, this entry is opted-in,
394 template_unlock(template);
784 * They must have been created from the same template.
943 ledger_track_maximum(ledger_template_t template, int entry,
946 template_lock(template);
948 if ((entry < 0) || (entry >= template->lt_cnt)) {
949 template_unlock(template);
953 template->lt_entries[entry].et_flags |= LF_TRACKING_MAX;
954 template_unlock(template);
960 ledger_panic_on_negative(ledger_template_t template, int entry)
962 template_lock(template);
964 if ((entry < 0) || (entry >= template->lt_cnt)) {
965 template_unlock(template);
969 template->lt_entries[entry].et_flags |= LF_PANIC_ON_NEGATIVE;
971 template_unlock(template);
979 ledger_set_callback(ledger_template_t template, int entry,
985 if ((entry < 0) || (entry >= template->lt_cnt))
997 template_lock(template);
998 et = &template->lt_entries[entry];
1001 template_unlock(template);
1011 * Otherwise, if using a ledger template which specified a
1487 * Since all tasks share a ledger template, we'll just use the