remove shared usb mutex

This commit is contained in:
akiroz 2022-01-27 03:47:18 +08:00
parent ad75199fed
commit 1be5f86c28
No known key found for this signature in database
GPG Key ID: 8A5957C4A2F68ACC

View File

@ -49,14 +49,12 @@ var slider_active = false;
var slider_thread: ?std.Thread = null;
var input_thread: ?std.Thread = null;
var usb_op = std.Thread.Mutex{};
var usb_in = std.mem.zeroes([0x24]u8);
var usb_out_op = std.Thread.Mutex{};
var usb_out = std.mem.zeroes([80*3]u8);
var usb_in = std.mem.zeroes([0x24]u8);
var tasoller: ?*anyopaque = null;
fn tasoller_init() !void {
usb_op.lock();
defer usb_op.unlock();
const hDevInfo = SetupDiGetClassDevsW(&GUID_DEVINTERFACE_USB_DEVICE, null, null, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
if(hDevInfo == INVALID_HANDLE_VALUE) {
@ -123,12 +121,10 @@ fn tasoller_init() !void {
// Poll input regardless of slider start/stop
fn input_thread_proc() void {
while(true) {
usb_op.lock();
var len: u32 = 0;
if(WinUsb_ReadPipe(tasoller, 0x84, @ptrCast(*u8, &usb_in), usb_in.len, &len, null) == 0) {
std.log.warn("[chuniio] WinUsb_ReadPipe: {any}", .{GetLastError()});
}
usb_op.unlock();
}
}
@ -220,8 +216,8 @@ export fn chuni_io_slider_set_leds(rgb: ?[*]u8) void {
out[n*3+2] = rgb.?[n*3+0];
}
usb_op.lock();
defer usb_op.unlock();
usb_out_op.lock();
defer usb_out_op.unlock();
if(WinUsb_WritePipe(tasoller, 0x03, @ptrCast(*u8, &usb_out), usb_out.len, &n, null) == 0) {
std.log.warn("[chuniio] WinUsb_WritePipe: {any}", .{GetLastError()});
}