[Spice-commits] server/char-device.c server/char-device.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Aug 2 10:58:00 UTC 2019
server/char-device.c | 27 +++++++++++++++------------
server/char-device.h | 2 +-
2 files changed, 16 insertions(+), 13 deletions(-)
New commits:
commit f584a5d6b6a189b3531f4e52c97b02f57956d47e
Author: Frediano Ziglio <fziglio at redhat.com>
Date: Thu May 30 06:21:20 2019 +0100
char-device: Allocate all write buffer in a single block
There are no much data other than the buffer, reduce the
allocations.
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Acked-by: Victor Toso <victortoso at redhat.com>
diff --git a/server/char-device.c b/server/char-device.c
index b0b4ef6c..a22a4ec5 100644
--- a/server/char-device.c
+++ b/server/char-device.c
@@ -149,11 +149,9 @@ red_char_device_remove_client(RedCharDevice *dev, RedClient *client)
static void red_char_device_write_buffer_free(RedCharDeviceWriteBuffer *buf)
{
- if (buf == NULL)
- return;
-
- g_free(buf->buf);
- g_free(buf);
+ if (buf) {
+ g_free(buf->priv);
+ }
}
static void write_buffers_queue_free(GQueue *write_queue)
@@ -533,22 +531,27 @@ red_char_device_write_buffer_get(RedCharDevice *dev, RedClient *client, int size
ret = g_queue_pop_tail(&dev->priv->write_bufs_pool);
if (ret) {
dev->priv->cur_pool_size -= ret->buf_size;
- } else {
+ if (ret->buf_size < size) {
+ spice_assert(!spice_extra_checks || ret->priv->refs == 1);
+ red_char_device_write_buffer_free(ret);
+ ret = NULL;
+ }
+ }
+ if (ret == NULL) {
struct RedCharDeviceWriteBufferFull {
- RedCharDeviceWriteBuffer buffer;
RedCharDeviceWriteBufferPrivate priv;
+ RedCharDeviceWriteBuffer buffer;
} *write_buf;
- write_buf = g_new0(struct RedCharDeviceWriteBufferFull, 1);
+ write_buf = g_malloc(sizeof(struct RedCharDeviceWriteBufferFull) + size);
+ memset(write_buf, 0, sizeof(*write_buf));
+ write_buf->priv.refs = 1;
ret = &write_buf->buffer;
+ ret->buf_size = size;
ret->priv = &write_buf->priv;
}
spice_assert(!ret->buf_used);
- if (ret->buf_size < size) {
- ret->buf = g_realloc(ret->buf, size);
- ret->buf_size = size;
- }
ret->priv->origin = origin;
if (origin == WRITE_BUFFER_ORIGIN_CLIENT) {
diff --git a/server/char-device.h b/server/char-device.h
index f4aae93d..7c5fb6c0 100644
--- a/server/char-device.h
+++ b/server/char-device.h
@@ -151,11 +151,11 @@ GType red_char_device_get_type(void) G_GNUC_CONST;
/* buffer that is used for writing to the device */
typedef struct RedCharDeviceWriteBufferPrivate RedCharDeviceWriteBufferPrivate;
typedef struct RedCharDeviceWriteBuffer {
- uint8_t *buf;
uint32_t buf_size;
uint32_t buf_used;
RedCharDeviceWriteBufferPrivate *priv;
+ uint8_t buf[0];
} RedCharDeviceWriteBuffer;
void red_char_device_reset_dev_instance(RedCharDevice *dev,
More information about the Spice-commits
mailing list