summaryrefslogtreecommitdiffstats
path: root/src/connection.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2011-11-17 16:46:36 -0500
committerKristian Høgsberg <krh@bitplanet.net>2011-11-17 17:52:01 -0500
commit4abc56bd6d476cf386fcc998d40e3d7753a2b03e (patch)
tree5223cfca93756e393b116d1f7a40bec97ba79746 /src/connection.c
parentAdd display event to acknowledge ID deletion (diff)
downloadwayland-4abc56bd6d476cf386fcc998d40e3d7753a2b03e.tar
wayland-4abc56bd6d476cf386fcc998d40e3d7753a2b03e.tar.gz
wayland-4abc56bd6d476cf386fcc998d40e3d7753a2b03e.tar.bz2
wayland-4abc56bd6d476cf386fcc998d40e3d7753a2b03e.tar.lz
wayland-4abc56bd6d476cf386fcc998d40e3d7753a2b03e.tar.xz
wayland-4abc56bd6d476cf386fcc998d40e3d7753a2b03e.tar.zst
wayland-4abc56bd6d476cf386fcc998d40e3d7753a2b03e.zip
Introduce wl_resource_queue_event() for sending events later
Some events, such as the display.delete_id, aren't very urgent and we would like to not always send them immdiately and cause an unnecessary context switch. The wl_resource_queue_event() function will place the event in the connection output buffer but not request the main loop to poll for writable. The effect is that the event will just sit in the output buffer until a more important event comes around and requires flushing.
Diffstat (limited to 'src/connection.c')
-rw-r--r--src/connection.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/connection.c b/src/connection.c
index 4230f7d..5a7ec2e 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -65,6 +65,7 @@ struct wl_connection {
void *data;
wl_connection_update_func_t update;
struct wl_closure receive_closure, send_closure;
+ int write_signalled;
};
union wl_value {
@@ -285,10 +286,13 @@ wl_connection_data(struct wl_connection *connection, uint32_t mask)
close_fds(&connection->fds_out);
connection->out.tail += len;
- if (connection->out.tail == connection->out.head)
+ if (connection->out.tail == connection->out.head &&
+ connection->write_signalled) {
connection->update(connection,
WL_CONNECTION_READABLE,
connection->data);
+ connection->write_signalled = 0;
+ }
}
if (mask & WL_CONNECTION_READABLE) {
@@ -334,11 +338,24 @@ wl_connection_write(struct wl_connection *connection,
wl_buffer_put(&connection->out, data, count);
- if (connection->out.head - connection->out.tail == count)
+ if (!connection->write_signalled) {
connection->update(connection,
WL_CONNECTION_READABLE |
WL_CONNECTION_WRITABLE,
connection->data);
+ connection->write_signalled = 1;
+ }
+}
+
+static void
+wl_connection_queue(struct wl_connection *connection,
+ const void *data, size_t count)
+{
+ if (connection->out.head - connection->out.tail +
+ count > ARRAY_LENGTH(connection->out.data))
+ wl_connection_data(connection, WL_CONNECTION_WRITABLE);
+
+ wl_buffer_put(&connection->out, data, count);
}
static int
@@ -704,6 +721,15 @@ wl_closure_send(struct wl_closure *closure, struct wl_connection *connection)
}
void
+wl_closure_queue(struct wl_closure *closure, struct wl_connection *connection)
+{
+ uint32_t size;
+
+ size = closure->start[1] >> 16;
+ wl_connection_queue(connection, closure->start, size);
+}
+
+void
wl_closure_print(struct wl_closure *closure, struct wl_object *target, int send)
{
union wl_value *value;