almost finished update to Zig 0.16.0
This commit is contained in:
+18
-13
@@ -9,8 +9,8 @@ const Self = @This();
|
||||
pub const Interface = base.Fence;
|
||||
|
||||
interface: Interface,
|
||||
mutex: std.Thread.Mutex,
|
||||
condition: std.Thread.Condition,
|
||||
mutex: std.Io.Mutex,
|
||||
condition: std.Io.Condition,
|
||||
is_signaled: bool,
|
||||
|
||||
pub fn create(device: *Device, allocator: std.mem.Allocator, info: *const vk.FenceCreateInfo) VkError!*Self {
|
||||
@@ -29,8 +29,8 @@ pub fn create(device: *Device, allocator: std.mem.Allocator, info: *const vk.Fen
|
||||
|
||||
self.* = .{
|
||||
.interface = interface,
|
||||
.mutex = std.Thread.Mutex{},
|
||||
.condition = std.Thread.Condition{},
|
||||
.mutex = .init,
|
||||
.condition = .init,
|
||||
.is_signaled = info.flags.signaled_bit,
|
||||
};
|
||||
return self;
|
||||
@@ -55,26 +55,31 @@ pub fn reset(interface: *Interface) VkError!void {
|
||||
|
||||
pub fn signal(interface: *Interface) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const io = interface.owner.io();
|
||||
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
self.mutex.lock(io) catch return VkError.DeviceLost;
|
||||
defer self.mutex.unlock(io);
|
||||
|
||||
self.is_signaled = true;
|
||||
self.condition.broadcast();
|
||||
self.condition.broadcast(io);
|
||||
}
|
||||
|
||||
pub fn wait(interface: *Interface, timeout: u64) VkError!void {
|
||||
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
|
||||
const io = interface.owner.io();
|
||||
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
self.mutex.lock(io) catch return VkError.DeviceLost;
|
||||
defer self.mutex.unlock(io);
|
||||
|
||||
if (self.is_signaled) return;
|
||||
if (timeout == 0) return VkError.Timeout;
|
||||
|
||||
if (timeout == std.math.maxInt(@TypeOf(timeout))) {
|
||||
self.condition.wait(&self.mutex);
|
||||
} else {
|
||||
self.condition.timedWait(&self.mutex, timeout) catch return VkError.Timeout;
|
||||
if (timeout != std.math.maxInt(@TypeOf(timeout))) {
|
||||
const duration: std.Io.Clock.Duration = .{
|
||||
.raw = .fromNanoseconds(@intCast(timeout)),
|
||||
.clock = .cpu_process,
|
||||
};
|
||||
duration.sleep(io) catch return VkError.DeviceLost;
|
||||
}
|
||||
self.condition.wait(io, &self.mutex) catch return VkError.DeviceLost;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user