~mil/mepo

5bc44fee924ad3fa9d45dfce7e6ef5316bf7ebaa — Miles Alan 2 years ago fca72b3 stdin_repl
Lock stdin/sdl event loop through mutex
1 files changed, 6 insertions(+), 0 deletions(-)

M src/Mepo.zig
M src/Mepo.zig => src/Mepo.zig +6 -0
@@ 35,6 35,7 @@ fontsize_ui: u8 = 20,
help: bool = false,
lat: f64 = 0,
lon: f64 = 0,
mutex: std.Thread.Mutex,
overlay_debugbar: bool = true,
overlay_pindetails: bool = true,
pin_group_active: u8 = 0,


@@ 912,7 913,9 @@ pub fn event_loop_and_read_stdin(mepo: *@This()) !void {
    const buffer = try mepo.allocator.alloc(u8, 1024 * 100);
    while (try stdin.readUntilDelimiterOrEof(buffer, '\n')) |read_slice| {
        std.debug.print("Read {d} bytes, running input as mepolang\n", .{read_slice.len});
        mepo.mutex.lock();
        try mepo.mepolang_execute(read_slice);
        mepo.mutex.unlock();
        utilsdl.sdl_push_resize_event();
    }
}


@@ 929,6 932,7 @@ pub fn sdl_event_loop(mepo: *@This()) !void {
    var e: sdl.SDL_Event = undefined;

    while (true) {
        mepo.mutex.lock();
        // Redraw
        sdl.SDL_PumpEvents();
        const has_pending_motion_events = (sdl.SDL_TRUE == sdl.SDL_HasEvent(sdl.SDL_MOUSEMOTION));


@@ 961,6 965,7 @@ pub fn sdl_event_loop(mepo: *@This()) !void {
            pending = mepo.event_signal(sig);
            pending_signal = null;
        }
        mepo.mutex.unlock();
    }
}



@@ 1326,6 1331,7 @@ pub fn init(allocator: std.mem.Allocator, tile_cache: *TileCache, use_sw_rendere
            break :fonts fonts;
        },
        .fingers = std.ArrayList(sdl.SDL_FingerID).init(allocator),
        .mutex = std.Thread.Mutex{},
        .renderer = try utilsdl.errorcheck_ptr(sdl.SDL_Renderer, sdl.SDL_CreateRenderer(
            window,
            -1,