libsysprof-capture: sleep and try again to get an event

Unless we've failed before, then just bail immediately so that applications
which loose their controller keep running with minimal overhead.
This commit is contained in:
Christian Hergert
2023-08-15 15:37:24 -07:00
parent b96bf5c969
commit c45aba997d

View File

@ -69,6 +69,7 @@ struct _MappedRingBuffer
void *map; void *map;
size_t body_size; size_t body_size;
size_t page_size; size_t page_size;
unsigned has_failed : 1;
}; };
static inline MappedRingHeader * static inline MappedRingHeader *
@ -405,6 +406,8 @@ mapped_ring_buffer_allocate (MappedRingBuffer *self,
assert (length < self->body_size); assert (length < self->body_size);
assert ((length & 0x7) == 0); assert ((length & 0x7) == 0);
for (unsigned i = 0; i < 1000; i++)
{
header = get_header (self); header = get_header (self);
__atomic_load (&header->head, &headpos, __ATOMIC_SEQ_CST); __atomic_load (&header->head, &headpos, __ATOMIC_SEQ_CST);
__atomic_load (&header->tail, &tailpos, __ATOMIC_SEQ_CST); __atomic_load (&header->tail, &tailpos, __ATOMIC_SEQ_CST);
@ -427,6 +430,14 @@ mapped_ring_buffer_allocate (MappedRingBuffer *self,
if (tailpos + length < headpos) if (tailpos + length < headpos)
return get_body_at_pos (self, tailpos); return get_body_at_pos (self, tailpos);
if (self->has_failed)
break;
usleep (1000); /* 1 msec */
}
self->has_failed = true;
return NULL; return NULL;
} }