return 2;
}
-static unsigned char*
-shared_data_find_room (int size)
+static SharedHeader*
+shared_data_reserve_room (int size, int ftype)
{
+ SharedHeader* header;
unsigned char *p = (unsigned char *)shared_area + shared_area->data_start;
unsigned char *end = (unsigned char *)shared_area + shared_area->size;
unsigned short *next;
if (*p == FTYPE_END) {
if (size < (end - p))
- return p;
+ goto res;
return NULL;
}
if (p + 4 > end)
if (*p == FTYPE_DELETED) {
/* we reuse only if it's the same size */
if (*next == size) {
- return p;
+ goto res;
}
}
p += *next;
}
return NULL;
+
+res:
+ header = (SharedHeader*)p;
+ header->ftype = ftype;
+ header->extra = 0; /* data_offset could overflow here, so we leave this field unused */
+ header->size = size;
+
+ return header;
}
typedef gboolean (*SharedFunc) (SharedHeader *header, void *data);
custom_get_instance (SharedCategory *cat, SharedCounter *scounter, MonoString* instance)
{
SharedInstance* inst;
- unsigned char *ptr;
char *p;
int size, data_offset;
char *name;
data_offset = size;
size += (sizeof (guint64) * cat->num_counters);
perfctr_lock ();
- ptr = shared_data_find_room (size);
- if (!ptr) {
+ inst = (SharedInstance*) shared_data_reserve_room (size, FTYPE_INSTANCE);
+ if (!inst) {
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);
char *name = NULL;
char *chelp = NULL;
char **counter_info = NULL;
- unsigned char *ptr;
char *p;
SharedCategory *cat;
if (size > 65535)
goto failure;
perfctr_lock ();
- ptr = shared_data_find_room (size);
- if (!ptr) {
+ cat = (SharedCategory*) shared_data_reserve_room (size, FTYPE_CATEGORY);
+ if (!cat) {
perfctr_unlock ();
goto failure;
}
- cat = (SharedCategory*)ptr;
- cat->header.extra = type;
- cat->header.size = size;
cat->num_counters = num_counters;
cat->counters_data_size = counters_data_size;
/* now copy the vaiable data */
strcpy (p, counter_info [i * 2 + 1]);
p += strlen (counter_info [i * 2 + 1]) + 1;
}
- cat->header.ftype = FTYPE_CATEGORY;
perfctr_unlock ();
result = TRUE;