<commit_before>//  Copyright © 2015 <NAME>. All rights reserved.

import Chip8Kit

final class Chip8Runner {
    private var _screen: [UInt8]?
    var screen: [UInt8]? {
        return get { self._screen }
    }
    
    private var _redraw = false
    var redraw: Bool {
        get { return get { self._redraw } }
        set { set { self._redraw = newValue } }
    }
    
    private var _playBeep = false
    var playBeep: Bool {
        get { return get { self._playBeep } }
        set { set { self._playBeep = newValue } }
    }
    
    private func get<T>(block: Void -> T) -> T {
        var value: T?
        dispatch_sync(queue) {
            value = block()
        }
        return value!
    }
    
    private func set(block: Void -> Void) {
        dispatch_async(queue, block)
    }
    
    private let queue = dispatch_queue_create("com.indragie.Chip8.Chip8Runner", DISPATCH_QUEUE_SERIAL)
    private let emulator: Emulator
    
    private lazy var CPUTimer: GCDTimer = {
        GCDTimer(interval: 1 / self.clockRate, queue: self.queue) { [unowned self] in
            do {
                let state = try self.emulator.emulateCycle()
                if state.redraw {
                    self._redraw = true
                }
                self._screen = state.screen
            } catch let error {
                fatalError("Emulation error: \(error)")
            }
        }
    }()
    private lazy var timerTimer: GCDTimer = {
        GCDTimer(interval: 1 / Emulator.Hardware.TimerClockRate, queue: self.queue) { [unowned self] in
            if self.emulator.emulateTimerTick() {
                self._playBeep = true
            }
        }<commit_msg>Capture weak ref in timer callbacks<commit_after>//  Copyright © 2015 <NAME>. All rights reserved.

import Chip8Kit

final class Chip8Runner {
    private var _screen: [UInt8]?
    var screen: [UInt8]? {
        return get { self._screen }
    }
    
    private var _redraw = false
    var redraw: Bool {
        get { return get { self._redraw } }
        set { set { self._redraw = newValue } }
    }
    
    private var _playBeep = false
    var playBeep: Bool {
        get { return get { self._playBeep } }
        set { set { self._playBeep = newValue } }
    }
    
    private func get<T>(block: Void -> T) -> T {
        var value: T?
        dispatch_sync(queue) {
            value = block()
        }
        return value!
    }
    
    private func set(block: Void -> Void) {
        dispatch_async(queue, block)
    }
    
    private let queue = dispatch_queue_create("com.indragie.Chip8.Chip8Runner", DISPATCH_QUEUE_SERIAL)
    private let emulator: Emulator
    
    private lazy var CPUTimer: GCDTimer = {
        GCDTimer(interval: 1 / self.clockRate, queue: self.queue) { [weak self] in
            guard let strongSelf = self else { return }
            do {
                let state = try strongSelf.emulator.emulateCycle()
                if state.redraw {
                    strongSelf._redraw = true
                }
                strongSelf._screen = state.screen
            } catch let error {
                fatalError("Emulation error: \(error)")
            }
        }
    }()
    private lazy var timerTimer: GCDTimer = {
        GCDTimer(interval: 1 / Emulator.Hardware.TimerClockRate, queue: self.queue) { [weak self] in
            guard let strongSelf = self else { return }
            
            if strongSelf.emulator.emulateTimerTick() {
                strongSelf._playBeep = true
            }
        }
{'fraction_non_alphanumeric': 0.09314140558848434, 'fraction_numerical': 0.006773920406435224, 'mean_word_length': 1.6868840030326004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6576176', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1026, 'n_words': 277}