[sysprof] capture: use uint for requested counter id
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sysprof] capture: use uint for requested counter id
- Date: Thu, 17 May 2018 11:20:12 +0000 (UTC)
commit 3d14ce4eaa999d881b7497ff12b7388661c13a08
Author: Christian Hergert <chergert redhat com>
Date: Thu May 17 12:19:54 2018 +0100
capture: use uint for requested counter id
Also document this thing so it is more obvious what is going on with the
resulting counter ranges.
lib/capture/sp-capture-writer.c | 18 +++++++++++++++++-
lib/capture/sp-capture-writer.h | 2 +-
2 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/lib/capture/sp-capture-writer.c b/lib/capture/sp-capture-writer.c
index 8ccc534..d61490d 100644
--- a/lib/capture/sp-capture-writer.c
+++ b/lib/capture/sp-capture-writer.c
@@ -1150,7 +1150,20 @@ sp_capture_writer_set_counters (SpCaptureWriter *self,
return TRUE;
}
-gint
+/**
+ * sp_capture_writer_request_counter:
+ *
+ * This requests a series of counter identifiers for the capture.
+ *
+ * The returning number is always greater than zero. The resulting counter
+ * values are monotonic starting from the resulting value.
+ *
+ * For example, if you are returned 5, and requested 3 counters, the counter
+ * ids you should use are 5, 6, and 7.
+ *
+ * Returns: The next series of counter values or zero on failure.
+ */
+guint
sp_capture_writer_request_counter (SpCaptureWriter *self,
guint n_counters)
{
@@ -1158,6 +1171,9 @@ sp_capture_writer_request_counter (SpCaptureWriter *self,
g_assert (self != NULL);
+ if (G_MAXUINT - n_counters < self->next_counter_id)
+ return 0;
+
ret = self->next_counter_id;
self->next_counter_id += n_counters;
diff --git a/lib/capture/sp-capture-writer.h b/lib/capture/sp-capture-writer.h
index 1867058..c2d2ae9 100644
--- a/lib/capture/sp-capture-writer.h
+++ b/lib/capture/sp-capture-writer.h
@@ -106,7 +106,7 @@ gboolean sp_capture_writer_flush (SpCaptureWriter *
gboolean sp_capture_writer_save_as (SpCaptureWriter *self,
const gchar *filename,
GError **error);
-gint sp_capture_writer_request_counter (SpCaptureWriter *self,
+guint sp_capture_writer_request_counter (SpCaptureWriter *self,
guint n_counters);
SpCaptureReader *sp_capture_writer_create_reader (SpCaptureWriter *self,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]