[sysprof: 15/63] libsysprof-capture: Replace G_{UN, }LIKELY with SYSPROF_{UN, }LIKELY
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof: 15/63] libsysprof-capture: Replace G_{UN, }LIKELY with SYSPROF_{UN, }LIKELY
- Date: Sat, 4 Jul 2020 18:30:35 +0000 (UTC)
commit f925fab56441a7a7815f545122a2ca8cb78834dd
Author: Philip Withnall <withnall endlessm com>
Date: Wed Jul 1 16:52:19 2020 +0100
libsysprof-capture: Replace G_{UN,}LIKELY with SYSPROF_{UN,}LIKELY
This does the same thing for modern compilers, but without the GLib
dependency.
Signed-off-by: Philip Withnall <withnall endlessm com>
Helps: #40
src/libsysprof-capture/sysprof-capture-condition.c | 2 +-
src/libsysprof-capture/sysprof-capture-reader.c | 26 +++++++++++-----------
src/libsysprof-capture/sysprof-capture-util.c | 3 ++-
src/libsysprof-capture/sysprof-capture-writer.c | 4 ++--
src/libsysprof-capture/sysprof-clock.h | 2 +-
src/libsysprof-capture/sysprof-collector.c | 10 ++++-----
src/libsysprof-capture/sysprof-macros.h | 8 +++++++
7 files changed, 32 insertions(+), 23 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-condition.c
b/src/libsysprof-capture/sysprof-capture-condition.c
index ea3aea6..febeeba 100644
--- a/src/libsysprof-capture/sysprof-capture-condition.c
+++ b/src/libsysprof-capture/sysprof-capture-condition.c
@@ -340,7 +340,7 @@ sysprof_capture_condition_new_where_time_between (int64_t begin_time,
{
SysprofCaptureCondition *self;
- if G_UNLIKELY (begin_time > end_time)
+ if SYSPROF_UNLIKELY (begin_time > end_time)
{
int64_t tmp = begin_time;
begin_time = end_time;
diff --git a/src/libsysprof-capture/sysprof-capture-reader.c b/src/libsysprof-capture/sysprof-capture-reader.c
index 59ce530..5222547 100644
--- a/src/libsysprof-capture/sysprof-capture-reader.c
+++ b/src/libsysprof-capture/sysprof-capture-reader.c
@@ -282,7 +282,7 @@ sysprof_capture_reader_bswap_frame (SysprofCaptureReader *self,
assert (self != NULL);
assert (frame!= NULL);
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
{
frame->len = GUINT16_SWAP_LE_BE (frame->len);
frame->cpu = GUINT16_SWAP_LE_BE (frame->cpu);
@@ -298,7 +298,7 @@ sysprof_capture_reader_bswap_file_chunk (SysprofCaptureReader *self,
assert (self != NULL);
assert (file_chunk != NULL);
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
file_chunk->len = GUINT16_SWAP_LE_BE (file_chunk->len);
}
@@ -309,7 +309,7 @@ sysprof_capture_reader_bswap_log (SysprofCaptureReader *self,
assert (self != NULL);
assert (log != NULL);
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
log->severity = GUINT16_SWAP_LE_BE (log->severity);
}
@@ -320,7 +320,7 @@ sysprof_capture_reader_bswap_map (SysprofCaptureReader *self,
assert (self != NULL);
assert (map != NULL);
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
{
map->start = GUINT64_SWAP_LE_BE (map->start);
map->end = GUINT64_SWAP_LE_BE (map->end);
@@ -336,7 +336,7 @@ sysprof_capture_reader_bswap_mark (SysprofCaptureReader *self,
assert (self != NULL);
assert (mark != NULL);
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
mark->duration = GUINT64_SWAP_LE_BE (mark->duration);
}
@@ -347,7 +347,7 @@ sysprof_capture_reader_bswap_jitmap (SysprofCaptureReader *self,
assert (self != NULL);
assert (jitmap != NULL);
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
jitmap->n_jitmaps = GUINT64_SWAP_LE_BE (jitmap->n_jitmaps);
}
@@ -531,7 +531,7 @@ sysprof_capture_reader_read_fork (SysprofCaptureReader *self)
if (fk != NULL)
{
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
fk->child_pid = GUINT32_SWAP_LE_BE (fk->child_pid);
}
@@ -660,7 +660,7 @@ sysprof_capture_reader_read_mark (SysprofCaptureReader *self)
((char *)mark)[mark->frame.len - 1] = 0;
/* Maybe update end-time */
- if G_UNLIKELY ((mark->frame.time + mark->duration) > self->end_time)
+ if SYSPROF_UNLIKELY ((mark->frame.time + mark->duration) > self->end_time)
self->end_time = mark->frame.time + mark->duration;
return mark;
@@ -843,7 +843,7 @@ sysprof_capture_reader_read_sample (SysprofCaptureReader *self)
sample = (SysprofCaptureSample *)(void *)&self->buf[self->pos];
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
{
unsigned int i;
@@ -876,7 +876,7 @@ sysprof_capture_reader_read_counter_define (SysprofCaptureReader *self)
if (def->frame.len < sizeof *def)
return NULL;
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
def->n_counters = GUINT16_SWAP_LE_BE (def->n_counters);
if (def->frame.len < (sizeof *def + (sizeof (SysprofCaptureCounterDefine) * def->n_counters)))
@@ -887,7 +887,7 @@ sysprof_capture_reader_read_counter_define (SysprofCaptureReader *self)
def = (SysprofCaptureCounterDefine *)(void *)&self->buf[self->pos];
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
{
unsigned int i;
@@ -934,7 +934,7 @@ sysprof_capture_reader_read_counter_set (SysprofCaptureReader *self)
set = (SysprofCaptureCounterSet *)(void *)&self->buf[self->pos];
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
{
unsigned int i;
@@ -1424,7 +1424,7 @@ sysprof_capture_reader_read_allocation (SysprofCaptureReader *self)
ma = (SysprofCaptureAllocation *)(void *)&self->buf[self->pos];
- if (G_UNLIKELY (self->endian != G_BYTE_ORDER))
+ if (SYSPROF_UNLIKELY (self->endian != G_BYTE_ORDER))
{
for (unsigned int i = 0; i < ma->n_addrs; i++)
ma->addrs[i] = GUINT64_SWAP_LE_BE (ma->addrs[i]);
diff --git a/src/libsysprof-capture/sysprof-capture-util.c b/src/libsysprof-capture/sysprof-capture-util.c
index 3281172..75f9b26 100644
--- a/src/libsysprof-capture/sysprof-capture-util.c
+++ b/src/libsysprof-capture/sysprof-capture-util.c
@@ -70,6 +70,7 @@
#endif
#include "sysprof-capture-util-private.h"
+#include "sysprof-macros.h"
#ifdef G_OS_WIN32
static G_LOCK_DEFINE (_sysprof_io_sync);
@@ -80,7 +81,7 @@ size_t
{
static size_t pgsz = 0;
- if G_UNLIKELY (pgsz == 0)
+ if SYSPROF_UNLIKELY (pgsz == 0)
{
#ifdef G_OS_WIN32
SYSTEM_INFO system_info;
diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c
index 16bf753..d4aa2fc 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.c
+++ b/src/libsysprof-capture/sysprof-capture-writer.c
@@ -433,7 +433,7 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
{
SysprofCaptureJitmapBucket *bucket = &self->addr_hash[i];
- if (G_LIKELY (bucket->str == NULL))
+ if (SYSPROF_LIKELY (bucket->str == NULL))
{
bucket->str = dst;
bucket->addr = addr;
@@ -447,7 +447,7 @@ sysprof_capture_writer_insert_jitmap (SysprofCaptureWriter *self,
{
SysprofCaptureJitmapBucket *bucket = &self->addr_hash[i];
- if (G_LIKELY (bucket->str == NULL))
+ if (SYSPROF_LIKELY (bucket->str == NULL))
{
bucket->str = dst;
bucket->addr = addr;
diff --git a/src/libsysprof-capture/sysprof-clock.h b/src/libsysprof-capture/sysprof-clock.h
index 54695cb..523b596 100644
--- a/src/libsysprof-capture/sysprof-clock.h
+++ b/src/libsysprof-capture/sysprof-clock.h
@@ -80,7 +80,7 @@ sysprof_clock_get_current_time (void)
struct timespec ts;
SysprofClock clock = sysprof_clock;
- if G_UNLIKELY (clock == -1)
+ if SYSPROF_UNLIKELY (clock == -1)
clock = CLOCK_MONOTONIC;
clock_gettime (clock, &ts);
diff --git a/src/libsysprof-capture/sysprof-collector.c b/src/libsysprof-capture/sysprof-collector.c
index 938a950..9c72d0b 100644
--- a/src/libsysprof-capture/sysprof-collector.c
+++ b/src/libsysprof-capture/sysprof-collector.c
@@ -224,10 +224,10 @@ sysprof_collector_get (void)
const SysprofCollector *collector = g_private_get (&collector_key);
/* We might have gotten here recursively */
- if G_UNLIKELY (collector == COLLECTOR_INVALID)
+ if SYSPROF_UNLIKELY (collector == COLLECTOR_INVALID)
return COLLECTOR_INVALID;
- if G_LIKELY (collector != NULL)
+ if SYSPROF_LIKELY (collector != NULL)
return collector;
if (use_single_trace () && shared_collector != COLLECTOR_INVALID)
@@ -278,9 +278,9 @@ sysprof_collector_init (void)
#define COLLECTOR_BEGIN \
G_STMT_START { \
const SysprofCollector *collector = sysprof_collector_get (); \
- if G_LIKELY (collector->buffer) \
+ if SYSPROF_LIKELY (collector->buffer) \
{ \
- if G_UNLIKELY (collector->is_shared) \
+ if SYSPROF_UNLIKELY (collector->is_shared) \
G_LOCK (control_fd); \
\
{
@@ -288,7 +288,7 @@ sysprof_collector_init (void)
#define COLLECTOR_END \
} \
\
- if G_UNLIKELY (collector->is_shared) \
+ if SYSPROF_UNLIKELY (collector->is_shared) \
G_UNLOCK (control_fd); \
} \
} G_STMT_END
diff --git a/src/libsysprof-capture/sysprof-macros.h b/src/libsysprof-capture/sysprof-macros.h
index 241a41e..a7bcc04 100644
--- a/src/libsysprof-capture/sysprof-macros.h
+++ b/src/libsysprof-capture/sysprof-macros.h
@@ -72,3 +72,11 @@
#else
#define SYSPROF_INTERNAL
#endif
+
+#if defined(__GNUC__)
+#define SYSPROF_LIKELY(expr) (__builtin_expect (!!(expr), 1))
+#define SYSPROF_UNLIKELY(expr) (__builtin_expect (!!(expr), 0))
+#else
+#define SYSPROF_LIKELY(expr) (expr)
+#define SYSPROF_UNLIKELY(expr) (expr)
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]