<commit_before>//
//  ThreadManager.swift
//  Music
//
//  Created by Jack on 5/22/17.
//  Copyright © 2017 Jack. All rights reserved.
//

import Foundation

class ThreadManager {
    static let `default`: ThreadManager = ThreadManager()
    
    /// Audio parse serial queue
    let audioParseQueue: DispatchQueue
    
    /// Music resource manager cache / download queue
    let resourceQueue: DispatchQueue
    
    init() {
        audioParseQueue = DispatchQueue(label: "com.Music.ThreadManager.AudioParseQueue")
        resourceQueue = DispatchQueue(label: "com.Music.ThreadManager.MusicResourceManagerQueue",
                                      qos: .background)
    }
}<commit_msg>Modify ThreadManager<commit_after>//
//  ThreadManager.swift
//  Music
//
//  Created by Jack on 5/22/17.
//  Copyright © 2017 Jack. All rights reserved.
//

import Foundation

final class ThreadManager {
    
    static let `default`: ThreadManager = ThreadManager()
    
    /// Audio parse serial queue
    let audioParseQueue: DispatchQueue
    
    /// Music resource manager cache / download background queue
    let resourceQueue: DispatchQueue
    
    /// If is aleardy in main, it will execuse synchronous, or execuse asynchronous
    var main: SafeMainDispatchQueue { return SafeMainDispatchQueue.default }
    
    /// Music player queue
    var playerQueue: DispatchQueue { return DispatchQueue.global() }
    
    init() {
        audioParseQueue = DispatchQueue(label: "com.Music.ThreadManager.AudioParse.Serial")
        resourceQueue = DispatchQueue(label: "com.Music.ThreadManager.MusicResourceManager.background.Serial",
                                      qos: .background)
    }
}

final class SafeMainDispatchQueue {
    
    private let mainQueueKey = DispatchSpecificKey<String>()
    private let mainQueueValue: String = "com.Music.ThreadManager.main"
    
    fileprivate static let `default` = SafeMainDispatchQueue()
    
    private init() {
        DispatchQueue.main.setSpecific(key: mainQueueKey, value: mainQueueValue)
    }
    
    func async(execute work: @escaping () -> ()) {
        
        if DispatchQueue.getSpecific(key: SafeMainDispatchQueue.default.mainQueueKey) == SafeMainDispatchQueue.default.mainQueueValue {
            work()
        } else {
            DispatchQueue.main.async {
                work()
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09109991603694374, 'fraction_numerical': 0.007556675062972292, 'mean_word_length': 2.4636627906976742, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1205010', 'n_tokens_mistral': 655, 'n_tokens_neox': 623, 'n_words': 161}