qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Lieven <pl@kamp.de>, Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [RfC PATCH 04/10] io: add qio_buffer_init
Date: Thu, 24 Sep 2015 10:42:02 +0200	[thread overview]
Message-ID: <1443084128-25552-5-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1443084128-25552-1-git-send-email-kraxel@redhat.com>

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/io/buffer.h | 12 ++++++++++++
 io/buffer.c         | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/io/buffer.h b/include/io/buffer.h
index 2b1b261..cffad19 100644
--- a/include/io/buffer.h
+++ b/include/io/buffer.h
@@ -34,12 +34,24 @@ typedef struct QIOBuffer QIOBuffer;
  */
 
 struct QIOBuffer {
+    char *name;
     size_t capacity;
     size_t offset;
     uint8_t *buffer;
 };
 
 /**
+ * qio_buffer_init:
+ * @buffer: the buffer object
+ * @name: buffer name
+ *
+ * Optionally attach a name to the buffer, to make it easier
+ * to identify in debug traces.
+ */
+void qio_buffer_init(QIOBuffer *buffer, const char *name, ...)
+        GCC_FMT_ATTR(2, 3);
+
+/**
  * qio_buffer_reserve:
  * @buffer: the buffer object
  * @len: the minimum required free space
diff --git a/io/buffer.c b/io/buffer.c
index 6aa06e7..daa3ebf 100644
--- a/io/buffer.c
+++ b/io/buffer.c
@@ -22,6 +22,15 @@
 
 #define QIO_BUFFER_MIN_INIT_SIZE 4096
 
+void qio_buffer_init(QIOBuffer *buffer, const char *name, ...)
+{
+    va_list ap;
+
+    va_start(ap, name);
+    buffer->name = g_strdup_vprintf(name, ap);
+    va_end(ap);
+}
+
 void qio_buffer_reserve(QIOBuffer *buffer, size_t len)
 {
     if ((buffer->capacity - buffer->offset) < len) {
@@ -49,9 +58,11 @@ void qio_buffer_reset(QIOBuffer *buffer)
 void qio_buffer_free(QIOBuffer *buffer)
 {
     g_free(buffer->buffer);
+    g_free(buffer->name);
     buffer->offset = 0;
     buffer->capacity = 0;
     buffer->buffer = NULL;
+    buffer->name = NULL;
 }
 
 void qio_buffer_append(QIOBuffer *buffer, const void *data, size_t len)
-- 
1.8.3.1

  parent reply	other threads:[~2015-09-24  8:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-24  8:41 [Qemu-devel] [RfC PATCH 00/10] vnc buffer handling Gerd Hoffmann
2015-09-24  8:41 ` [Qemu-devel] [RfC PATCH 01/10] io/ makefile fluff Gerd Hoffmann
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 02/10] io: pull Buffer code out of VNC module Gerd Hoffmann
2015-09-25  9:57   ` Peter Lieven
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 03/10] vnc: make the Buffer capacity increase in powers of two Gerd Hoffmann
2015-09-24  8:42 ` Gerd Hoffmann [this message]
2015-09-25  9:56   ` [Qemu-devel] [RfC PATCH 04/10] io: add qio_buffer_init Peter Lieven
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 05/10] io: add qio_buffer_move_empty Gerd Hoffmann
2015-09-25  9:56   ` Peter Lieven
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 06/10] io: add qio_buffer_move Gerd Hoffmann
2015-09-25  9:57   ` Peter Lieven
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 07/10] io: add qio_buffer tracing Gerd Hoffmann
2015-09-25  8:10   ` Peter Lieven
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 08/10] name vnc buffers Gerd Hoffmann
2015-09-25  7:28   ` Peter Lieven
2015-09-25  7:58   ` Peter Lieven
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 09/10] vnc: kill jobs queue buffer Gerd Hoffmann
2015-09-25  9:57   ` Peter Lieven
2015-09-24  8:42 ` [Qemu-devel] [RfC PATCH 10/10] vnc-jobs: move buffer reset, use new buffer move Gerd Hoffmann
2015-09-25  9:39   ` Peter Lieven
2015-09-24 16:25 ` [Qemu-devel] [RfC PATCH 00/10] vnc buffer handling Daniel P. Berrange
2015-09-25  9:56 ` Peter Lieven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1443084128-25552-5-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).