Don't recreate transaction timer unnecessarily
This commit is contained in:
parent
95175d3115
commit
eaf13f3bcf
@ -48,7 +48,7 @@ xwayland_unmanaged_views: if (build_options.xwayland) std.TailQueue(XwaylandUnma
|
|||||||
pending_configures: u32,
|
pending_configures: u32,
|
||||||
|
|
||||||
/// Handles timeout of transactions
|
/// Handles timeout of transactions
|
||||||
transaction_timer: ?*c.wl_event_source,
|
transaction_timer: *c.wl_event_source,
|
||||||
|
|
||||||
pub fn init(self: *Self, server: *Server) !void {
|
pub fn init(self: *Self, server: *Server) !void {
|
||||||
self.server = server;
|
self.server = server;
|
||||||
@ -71,7 +71,11 @@ pub fn init(self: *Self, server: *Server) !void {
|
|||||||
|
|
||||||
self.pending_configures = 0;
|
self.pending_configures = 0;
|
||||||
|
|
||||||
self.transaction_timer = null;
|
self.transaction_timer = c.wl_event_loop_add_timer(
|
||||||
|
self.server.wl_event_loop,
|
||||||
|
handleTimeout,
|
||||||
|
self,
|
||||||
|
) orelse return error.CantCreateTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deinit(self: *Self) void {
|
pub fn deinit(self: *Self) void {
|
||||||
@ -157,16 +161,10 @@ fn startTransaction(self: *Self) void {
|
|||||||
.{self.pending_configures},
|
.{self.pending_configures},
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: log failure to create timer and commit immediately
|
|
||||||
self.transaction_timer = c.wl_event_loop_add_timer(
|
|
||||||
self.server.wl_event_loop,
|
|
||||||
handleTimeout,
|
|
||||||
self,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Set timeout to 200ms
|
// Set timeout to 200ms
|
||||||
if (c.wl_event_source_timer_update(self.transaction_timer, 200) == -1) {
|
if (c.wl_event_source_timer_update(self.transaction_timer, 200) < 0) {
|
||||||
// TODO: handle failure
|
Log.Error.log("failed to update timer.", .{});
|
||||||
|
self.commitTransaction();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.commitTransaction();
|
self.commitTransaction();
|
||||||
@ -186,10 +184,9 @@ fn handleTimeout(data: ?*c_void) callconv(.C) c_int {
|
|||||||
pub fn notifyConfigured(self: *Self) void {
|
pub fn notifyConfigured(self: *Self) void {
|
||||||
self.pending_configures -= 1;
|
self.pending_configures -= 1;
|
||||||
if (self.pending_configures == 0) {
|
if (self.pending_configures == 0) {
|
||||||
// Stop the timer, as we didn't timeout
|
// Disarm the timer, as we didn't timeout
|
||||||
if (c.wl_event_source_timer_update(self.transaction_timer, 0) == -1) {
|
if (c.wl_event_source_timer_update(self.transaction_timer, 0) == -1)
|
||||||
// TODO: handle failure
|
Log.Error.log("Error disarming timer", .{});
|
||||||
}
|
|
||||||
self.commitTransaction();
|
self.commitTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user