libuv: add more APIs

This commit is contained in:
Mitchell Hashimoto
2022-04-29 19:19:51 -07:00
parent f11531bc3f
commit e1a58c5cbc
2 changed files with 18 additions and 2 deletions

View File

@ -6,6 +6,7 @@ const Allocator = std.mem.Allocator;
const testing = std.testing; const testing = std.testing;
const c = @import("c.zig"); const c = @import("c.zig");
const errors = @import("error.zig"); const errors = @import("error.zig");
const Mutex = @import("Mutex.zig");
cond: *c.uv_cond_t, cond: *c.uv_cond_t,
@ -29,8 +30,12 @@ pub fn broadcast(self: Cond) void {
c.uv_cond_broadcast(self.cond); c.uv_cond_broadcast(self.cond);
} }
pub fn wait(self: Cond) void { pub fn wait(self: Cond, mutex: Mutex) void {
c.uv_cond_wait(self.cond); c.uv_cond_wait(self.cond, mutex.mutex);
}
pub fn timedwait(self: Cond, mutex: Mutex, timeout: u64) c_int {
return c.uv_cond_timedwait(self.cond, mutex.mutex, timeout);
} }
test { test {

View File

@ -79,6 +79,17 @@ pub fn now(self: Loop) u64 {
return c.uv_now(self.loop); return c.uv_now(self.loop);
} }
/// Update the event loops concept of now. Libuv caches the current time at
/// the start of the event loop tick in order to reduce the number of time-related
/// system calls.
///
/// You wont normally need to call this function unless you have callbacks
/// that block the event loop for longer periods of time, where longer is
/// somewhat subjective but probably on the order of a millisecond or more.
pub fn updateTime(self: Loop) void {
return c.uv_update_time(self.loop);
}
/// Sets loop->data to data. /// Sets loop->data to data.
pub fn setData(self: Loop, pointer: ?*anyopaque) void { pub fn setData(self: Loop, pointer: ?*anyopaque) void {
c.uv_loop_set_data(self.loop, pointer); c.uv_loop_set_data(self.loop, pointer);