Lines Matching defs:template
110 #define template_lock(template) lck_mtx_lock(&(template)->lt_lock)
111 #define template_unlock(template) lck_mtx_unlock(&(template)->lt_lock)
194 ledger_template_t template;
196 template = (ledger_template_t)kalloc(sizeof (*template));
197 if (template == NULL)
200 template->lt_name = name;
201 template->lt_refs = 1;
202 template->lt_cnt = 0;
203 template->lt_table_size = 1;
204 template->lt_inuse = 0;
205 lck_mtx_init(&template->lt_lock, &ledger_lck_grp, LCK_ATTR_NULL);
207 template->lt_entries = (struct entry_template *)
208 kalloc(sizeof (struct entry_template) * template->lt_table_size);
209 if (template->lt_entries == NULL) {
210 kfree(template, sizeof (*template));
211 template = NULL;
214 return (template);
218 ledger_template_dereference(ledger_template_t template)
220 template_lock(template);
221 template->lt_refs--;
222 template_unlock(template);
224 if (template->lt_refs == 0)
225 kfree(template, sizeof (*template));
229 * Add a new entry to the list of entries in a ledger template. There is
235 ledger_entry_add(ledger_template_t template, const char *key,
244 template_lock(template);
247 if (template->lt_cnt == template->lt_table_size) {
252 old_cnt = template->lt_table_size;
256 template_unlock(template);
259 memcpy(new_entries, template->lt_entries, old_sz);
261 template->lt_table_size = old_cnt * 2;
263 old_entries = template->lt_entries;
265 TEMPLATE_INUSE(s, template);
266 template->lt_entries = new_entries;
267 TEMPLATE_IDLE(s, template);
272 et = &template->lt_entries[template->lt_cnt];
279 idx = template->lt_cnt++;
280 template_unlock(template);
303 ledger_key_lookup(ledger_template_t template, const char *key)
307 template_lock(template);
308 for (idx = 0; idx < template->lt_cnt; idx++)
309 if (template->lt_entries[idx].et_key &&
310 (strcmp(key, template->lt_entries[idx].et_key) == 0))
313 if (idx >= template->lt_cnt)
315 template_unlock(template);
321 * Create a new ledger based on the specified template. As part of the
323 * The size of the table is based on the size of the template at the time
324 * the ledger is created. If additional entries are added to the template
328 ledger_instantiate(ledger_template_t template, int entry_type)
338 ledger->l_template = template;
342 template_lock(template);
343 template->lt_refs++;
344 ledger->l_size = template->lt_cnt;
345 template_unlock(template);
350 ledger_template_dereference(template);
355 template_lock(template);
356 assert(ledger->l_size <= template->lt_cnt);
359 struct entry_template *et = &template->lt_entries[i];
366 * If template has a callback, this entry is opted-in,
376 template_unlock(template);
659 ledger_set_callback(ledger_template_t template, int entry,
665 if ((entry < 0) || (entry >= template->lt_cnt))
677 template_lock(template);
678 et = &template->lt_entries[entry];
681 template_unlock(template);
691 * Otherwise, if using a ledger template which specified a
975 * Since all tasks share a ledger template, we'll just use the