chore: be more intentional in atomic ordering use
This commit is contained in:
		@@ -56,7 +56,7 @@ fn inner(comptime kind: RunKind, audio_sync: bool, quit: *Atomic(bool), schedule
 | 
				
			|||||||
        .Unlimited, .UnlimitedFPS => {
 | 
					        .Unlimited, .UnlimitedFPS => {
 | 
				
			||||||
            log.info("Emulation w/out video sync", .{});
 | 
					            log.info("Emulation w/out video sync", .{});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            while (!quit.load(.SeqCst)) {
 | 
					            while (!quit.load(.Monotonic)) {
 | 
				
			||||||
                runFrame(scheduler, cpu);
 | 
					                runFrame(scheduler, cpu);
 | 
				
			||||||
                audioSync(audio_sync, cpu.bus.apu.stream, &cpu.bus.apu.is_buffer_full);
 | 
					                audioSync(audio_sync, cpu.bus.apu.stream, &cpu.bus.apu.is_buffer_full);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -68,7 +68,7 @@ fn inner(comptime kind: RunKind, audio_sync: bool, quit: *Atomic(bool), schedule
 | 
				
			|||||||
            var timer = Timer.start() catch @panic("failed to initalize std.timer.Timer");
 | 
					            var timer = Timer.start() catch @panic("failed to initalize std.timer.Timer");
 | 
				
			||||||
            var wake_time: u64 = frame_period;
 | 
					            var wake_time: u64 = frame_period;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            while (!quit.load(.SeqCst)) {
 | 
					            while (!quit.load(.Monotonic)) {
 | 
				
			||||||
                runFrame(scheduler, cpu);
 | 
					                runFrame(scheduler, cpu);
 | 
				
			||||||
                const new_wake_time = videoSync(&timer, wake_time);
 | 
					                const new_wake_time = videoSync(&timer, wake_time);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1464,7 +1464,7 @@ const FrameBuffer = struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    layers: [2][]u8,
 | 
					    layers: [2][]u8,
 | 
				
			||||||
    buf: []u8,
 | 
					    buf: []u8,
 | 
				
			||||||
    current: u1,
 | 
					    current: std.atomic.Atomic(u8),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    allocator: Allocator,
 | 
					    allocator: Allocator,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1483,7 +1483,7 @@ const FrameBuffer = struct {
 | 
				
			|||||||
            // Front and Back Framebuffers
 | 
					            // Front and Back Framebuffers
 | 
				
			||||||
            .layers = [_][]u8{ buf[0..][0..framebuf_len], buf[framebuf_len..][0..framebuf_len] },
 | 
					            .layers = [_][]u8{ buf[0..][0..framebuf_len], buf[framebuf_len..][0..framebuf_len] },
 | 
				
			||||||
            .buf = buf,
 | 
					            .buf = buf,
 | 
				
			||||||
            .current = 0,
 | 
					            .current = std.atomic.Atomic(u8).init(0),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            .allocator = allocator,
 | 
					            .allocator = allocator,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
@@ -1495,10 +1495,12 @@ const FrameBuffer = struct {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn swap(self: *Self) void {
 | 
					    pub fn swap(self: *Self) void {
 | 
				
			||||||
        self.current = ~self.current;
 | 
					        _ = self.current.fetchXor(1, .Release); // fetchNot(.Release)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn get(self: *Self, comptime dev: Device) []u8 {
 | 
					    pub fn get(self: *Self, comptime dev: Device) []u8 {
 | 
				
			||||||
        return self.layers[if (dev == .Emulator) self.current else ~self.current];
 | 
					        const current = @intCast(u1, self.current.load(.Acquire));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return self.layers[if (dev == .Emulator) current else ~current];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -246,7 +246,7 @@ pub const Gui = struct {
 | 
				
			|||||||
            SDL.SDL_SetWindowTitle(self.window, dyn_title.ptr);
 | 
					            SDL.SDL_SetWindowTitle(self.window, dyn_title.ptr);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        quit.store(true, .SeqCst); // Terminate Emulator Thread
 | 
					        quit.store(true, .Monotonic); // Terminate Emulator Thread
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn deinit(self: *Self) void {
 | 
					    pub fn deinit(self: *Self) void {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -47,7 +47,7 @@ pub const FpsTracker = struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    pub fn value(self: *Self) u32 {
 | 
					    pub fn value(self: *Self) u32 {
 | 
				
			||||||
        if (self.timer.read() >= std.time.ns_per_s) {
 | 
					        if (self.timer.read() >= std.time.ns_per_s) {
 | 
				
			||||||
            self.fps = self.count.swap(0, .SeqCst);
 | 
					            self.fps = self.count.swap(0, .Monotonic);
 | 
				
			||||||
            self.timer.reset();
 | 
					            self.timer.reset();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user