+static SharedInstance*
+custom_get_instance (SharedCategory *cat, SharedCounter *scounter, MonoString* instance)
+{
+ SharedInstance* inst;
+ unsigned char *ptr;
+ char *p;
+ int size, data_offset;
+ char *name;
+ inst = find_custom_instance (cat, instance);
+ if (inst)
+ return inst;
+ name = mono_string_to_utf8 (instance);
+ size = sizeof (SharedInstance) + strlen (name);
+ size += 7;
+ size &= ~7;
+ data_offset = size;
+ size += (sizeof (guint64) * cat->num_counters);
+ perfctr_lock ();
+ ptr = shared_data_find_room (size);
+ if (!ptr) {
+ perfctr_unlock ();
+ g_free (name);
+ return NULL;
+ }
+ inst = (SharedInstance*)ptr;
+ inst->header.extra = 0; /* data_offset could overflow here, so we leave this field unused */
+ inst->header.size = size;
+ inst->category_offset = (char*)cat - (char*)shared_area;
+ cat->num_instances++;
+ /* now copy the variable data */
+ p = inst->instance_name;
+ strcpy (p, name);
+ p += strlen (name) + 1;
+ inst->header.ftype = FTYPE_INSTANCE;
+ perfctr_unlock ();
+ g_free (name);
+
+ return inst;
+}
+
+static ImplVtable*
+custom_vtable (SharedCounter *scounter, SharedInstance* inst, char *data)
+{
+ CustomVTable* vtable;
+ vtable = g_new0 (CustomVTable, 1);
+ vtable->vtable.arg = data;
+ vtable->vtable.sample = custom_writable_counter;
+ vtable->vtable.update = custom_writable_update;
+ vtable->instance_desc = inst;
+ vtable->counter_desc = scounter;
+
+ return (ImplVtable*)vtable;
+}
+