libsysprof-capture: Use intrinsic atomics rather than g_atomic_*()

Use the intrinsic atomics provided by the compiler, instead of GLib’s
wrapper around them. This should work for all modern compilers.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
This commit is contained in:
Philip Withnall
2020-07-01 17:00:36 +01:00
parent b6fb272865
commit 951b46fddf
5 changed files with 22 additions and 19 deletions

View File

@ -334,7 +334,7 @@ mapped_ring_buffer_unref (MappedRingBuffer *self)
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
if (__atomic_fetch_sub (&self->ref_count, 1, __ATOMIC_SEQ_CST) == 1)
mapped_ring_buffer_finalize (self);
}
@ -344,7 +344,7 @@ mapped_ring_buffer_ref (MappedRingBuffer *self)
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
__atomic_fetch_add (&self->ref_count, 1, __ATOMIC_SEQ_CST);
return self;
}
@ -395,8 +395,8 @@ mapped_ring_buffer_allocate (MappedRingBuffer *self,
assert ((length & 0x7) == 0);
header = get_header (self);
headpos = g_atomic_int_get (&header->head);
tailpos = g_atomic_int_get (&header->tail);
__atomic_load (&header->head, &headpos, __ATOMIC_SEQ_CST);
__atomic_load (&header->tail, &tailpos, __ATOMIC_SEQ_CST);
/* We need to check that there is enough space for @length at the
* current position in the write buffer. We cannot fully catch up
@ -463,7 +463,7 @@ mapped_ring_buffer_advance (MappedRingBuffer *self,
* we just update the position as the only way the head could have
* moved is forward.
*/
g_atomic_int_set (&header->tail, tail);
__atomic_store (&header->tail, &tail, __ATOMIC_SEQ_CST);
}
/**
@ -494,8 +494,8 @@ mapped_ring_buffer_drain (MappedRingBuffer *self,
assert (callback != NULL);
header = get_header (self);
headpos = g_atomic_int_get (&header->head);
tailpos = g_atomic_int_get (&header->tail);
__atomic_load (&header->head, &headpos, __ATOMIC_SEQ_CST);
__atomic_load (&header->tail, &tailpos, __ATOMIC_SEQ_CST);
assert (headpos < self->body_size);
assert (tailpos < self->body_size);
@ -515,6 +515,7 @@ mapped_ring_buffer_drain (MappedRingBuffer *self,
{
const void *data = get_body_at_pos (self, headpos);
size_t len = tailpos - headpos;
uint32_t new_headpos;
if (!callback (data, &len, user_data))
return false;
@ -525,9 +526,11 @@ mapped_ring_buffer_drain (MappedRingBuffer *self,
headpos += len;
if (headpos >= self->body_size)
g_atomic_int_set (&header->head, headpos - self->body_size);
new_headpos = headpos - self->body_size;
else
g_atomic_int_set (&header->head, headpos);
new_headpos = headpos;
__atomic_store (&header->head, &new_headpos, __ATOMIC_SEQ_CST);
}
return true;
@ -552,8 +555,8 @@ mapped_ring_buffer_is_empty (MappedRingBuffer *self)
header = get_header (self);
headpos = g_atomic_int_get (&header->head);
tailpos = g_atomic_int_get (&header->tail);
__atomic_load (&header->head, &headpos, __ATOMIC_SEQ_CST);
__atomic_load (&header->tail, &tailpos, __ATOMIC_SEQ_CST);
return headpos == tailpos;
}

View File

@ -303,7 +303,7 @@ sysprof_capture_condition_ref (SysprofCaptureCondition *self)
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
__atomic_fetch_add (&self->ref_count, 1, __ATOMIC_SEQ_CST);
return self;
}
@ -313,7 +313,7 @@ sysprof_capture_condition_unref (SysprofCaptureCondition *self)
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
if (__atomic_fetch_sub (&self->ref_count, 1, __ATOMIC_SEQ_CST) == 1)
sysprof_capture_condition_finalize (self);
}

View File

@ -110,7 +110,7 @@ sysprof_capture_cursor_ref (SysprofCaptureCursor *self)
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
__atomic_fetch_add (&self->ref_count, 1, __ATOMIC_SEQ_CST);
return self;
}
@ -126,7 +126,7 @@ sysprof_capture_cursor_unref (SysprofCaptureCursor *self)
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
if (__atomic_fetch_sub (&self->ref_count, 1, __ATOMIC_SEQ_CST) == 1)
sysprof_capture_cursor_finalize (self);
}

View File

@ -973,7 +973,7 @@ sysprof_capture_reader_ref (SysprofCaptureReader *self)
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
__atomic_fetch_add (&self->ref_count, 1, __ATOMIC_SEQ_CST);
return self;
}
@ -984,7 +984,7 @@ sysprof_capture_reader_unref (SysprofCaptureReader *self)
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
if (__atomic_fetch_sub (&self->ref_count, 1, __ATOMIC_SEQ_CST) == 1)
sysprof_capture_reader_finalize (self);
}

View File

@ -192,7 +192,7 @@ sysprof_capture_writer_ref (SysprofCaptureWriter *self)
assert (self != NULL);
assert (self->ref_count > 0);
g_atomic_int_inc (&self->ref_count);
__atomic_fetch_add (&self->ref_count, 1, __ATOMIC_SEQ_CST);
return self;
}
@ -203,7 +203,7 @@ sysprof_capture_writer_unref (SysprofCaptureWriter *self)
assert (self != NULL);
assert (self->ref_count > 0);
if (g_atomic_int_dec_and_test (&self->ref_count))
if (__atomic_fetch_sub (&self->ref_count, 1, __ATOMIC_SEQ_CST) == 1)
sysprof_capture_writer_finalize (self);
}