<commit_before>//
//  DispatchQueue.swift
//  Threader
//
//  Created by <NAME> on 4/26/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

/**
 `DispatchQueue` is a wrapper around GCD that makes dispatch calls simple and readable.
 
 - Async:           runs code asynchronously on a given `dispatch_queue_t`.
 - AsyncMain:       runs code asynchronously on the main queue.
 - AsyncGlobal:     runs code asynchronously on the global queue with a given `dispatch_queue_priority_t`.
 - AsyncAfter:      runs code asynchronously with a given delay (`NSTimeInterval`), and `dispatch_queue_t`.
 - Sync:            runs code synchronously on a given `dispatch_queue_t`.
 - Once:            runs code once and only once for the lifetime of the application.
 */
public enum DispatchQueue: CustomStringConvertible, CustomDebugStringConvertible {
    
    public typealias DispatchExecutionBlock = ((Void) -> (Void))
    
    case Async(dispatch_queue_t)
    case AsyncMain
    case AsyncGlobal(dispatch_queue_priority_t)
    case AsyncAfter(NSTimeInterval, dispatch_queue_t)
    case Sync(dispatch_queue_t)
    case Once(dispatch_once_t)
    
    /**
     Runs the code block with respect to the current dispatch option.
     
     - parameter block: The code block.
     */
    public func execute(block: DispatchExecutionBlock) {
        
        switch self {
        case .Async(let queue): dispatch_async(queue, block)
        case .AsyncMain:
            
            dispatch_async(dispatch_get_main_queue(), {
                block()
            })
            
        case .AsyncGlobal(let priority): dispatch_async(dispatch_get_global_queue(priority, 0), block)
        case .AsyncAfter(let time, let queue): dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))), queue, block)
        case .Sync(let queue): dispatch_sync(queue, block)
        case .Once(var token): dispatch_once(&token, block)
        }
        
    }
    
    /**
     Convenience function that returns the main dispatch queue.
     
     - returns: `dispatch_queue_t`. The main dispatch queue.
     */
    public static func mainQueue() -> dispatch_queue_t {
        return dispatch_get_main_queue()
    }
    
    /**
     Convenience function that returns a global dispatch queue with a given `dispatch_queue_priority_t`.
     
     - returns: `dispatch_queue_t`. A global dispatch queue.
     */
    public static func globalQueue(priority: dispatch_queue_priority_t) -> dispatch_queue_t {
        return dispatch_get_global_queue(priority, 0)
    }
    
    /**
     Convenience function that returns the global user interactive dispatch queue.
     
     - returns: `dispatch_queue_t`. The global user interactive dispatch queue.
     */
    public static func userInteractiveQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.rawValue), 0)
    }
    
    /**
     Convenience function that returns the global user initiated dispatch queue.
     
     - returns: `dispatch_queue_t`. The global user initiated dispatch queue.
     */
    public static func userInitiatedQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)
    }
    
    /**
     Convenience function that returns the global utility dispatch queue.
     
     - returns: `dispatch_queue_t`. The global utility dispatch queue.
     */
    public static func utilityQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_UTILITY.rawValue), 0)
    }
    
    /**
     Convenience function that returns the global background dispatch queue.
     
     - returns: `dispatch_queue_t`. The global background dispatch queue.
     */
    public static func backgroundQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_BACKGROUND.rawValue), 0)
    }
    
    public var description: String {
        switch self {
        case .Async(let queue): return "DispatchQueue.Async, Queue -> \(queue)"
        case .AsyncMain: return "DispatchQueue.AsyncMain"
        case .AsyncGlobal(let priority): return "DispatchQueue.AsyncGlobal, Priority -> \(priority)"
        case .AsyncAfter(let time, let queue): return "DispatchQueue.AsyncAfter, After -> \(time), Queue -> \(queue)"
        case .Sync(let queue): return "DispatchQueue.Sync, Queue -> \(queue)"
        case .Once(let token): return "DispatchQueue.Once, Token -> \(token)"
        }
    }
    
    public var debugDescription: String {
        return description
    }
    
}
<commit_msg>DispatchQueue: added support for dispatch_barrier_sync<commit_after>//
//  DispatchQueue.swift
//  Threader
//
//  Created by <NAME> on 4/26/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

/**
 `DispatchQueue` is a wrapper around GCD that makes dispatch calls simple and readable.
 
 - Async:           runs code asynchronously on a given `dispatch_queue_t`.
 - AsyncMain:       runs code asynchronously on the main queue.
 - AsyncGlobal:     runs code asynchronously on the global queue with a given `dispatch_queue_priority_t`.
 - AsyncAfter:      runs code asynchronously with a given delay (`NSTimeInterval`), and `dispatch_queue_t`.
 - Sync:            runs code synchronously on a given `dispatch_queue_t`.
 - BarrierSync:     runs code synchronously blocking on a given `dispatch_queue_t`.
 - Once:            runs code once and only once for the lifetime of the application.
 */
public enum DispatchQueue: CustomStringConvertible, CustomDebugStringConvertible {
    
    public typealias DispatchExecutionBlock = ((Void) -> (Void))
    
    case Async(dispatch_queue_t)
    case AsyncMain
    case AsyncGlobal(dispatch_queue_priority_t)
    case AsyncAfter(NSTimeInterval, dispatch_queue_t)
    case Sync(dispatch_queue_t)
    case BarrierSync(dispatch_queue_t)
    case Once(dispatch_once_t)
    
    /**
     Runs the code block with respect to the current dispatch option.
     
     - parameter block: The code block.
     */
    public func execute(block: DispatchExecutionBlock) {
        
        switch self {
        case .Async(let queue): dispatch_async(queue, block)
        case .AsyncMain:
            
            dispatch_async(dispatch_get_main_queue(), {
                block()
            })
            
        case .AsyncGlobal(let priority): dispatch_async(dispatch_get_global_queue(priority, 0), block)
        case .AsyncAfter(let time, let queue): dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))), queue, block)
        case .Sync(let queue): dispatch_sync(queue, block)
        case .BarrierSync(let queue): dispatch_barrier_sync(queue, block)
        case .Once(var token): dispatch_once(&token, block)
        }
        
    }
    
    /**
     Convenience function that returns the main dispatch queue.
     
     - returns: `dispatch_queue_t`. The main dispatch queue.
     */
    public static func mainQueue() -> dispatch_queue_t {
        return dispatch_get_main_queue()
    }
    
    /**
     Convenience function that returns a global dispatch queue with a given `dispatch_queue_priority_t`.
     
     - returns: `dispatch_queue_t`. A global dispatch queue.
     */
    public static func globalQueue(priority: dispatch_queue_priority_t) -> dispatch_queue_t {
        return dispatch_get_global_queue(priority, 0)
    }
    
    /**
     Convenience function that returns the global user interactive dispatch queue.
     
     - returns: `dispatch_queue_t`. The global user interactive dispatch queue.
     */
    public static func userInteractiveQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.rawValue), 0)
    }
    
    /**
     Convenience function that returns the global user initiated dispatch queue.
     
     - returns: `dispatch_queue_t`. The global user initiated dispatch queue.
     */
    public static func userInitiatedQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.rawValue), 0)
    }
    
    /**
     Convenience function that returns the global utility dispatch queue.
     
     - returns: `dispatch_queue_t`. The global utility dispatch queue.
     */
    public static func utilityQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_UTILITY.rawValue), 0)
    }
    
    /**
     Convenience function that returns the global background dispatch queue.
     
     - returns: `dispatch_queue_t`. The global background dispatch queue.
     */
    public static func backgroundQueue() -> dispatch_queue_t {
        return dispatch_get_global_queue(Int(QOS_CLASS_BACKGROUND.rawValue), 0)
    }
    
    public var description: String {
        switch self {
        case .Async(let queue): return "DispatchQueue.Async, Queue -> \(queue)"
        case .AsyncMain: return "DispatchQueue.AsyncMain"
        case .AsyncGlobal(let priority): return "DispatchQueue.AsyncGlobal, Priority -> \(priority)"
        case .AsyncAfter(let time, let queue): return "DispatchQueue.AsyncAfter, After -> \(time), Queue -> \(queue)"
        case .Sync(let queue): return "DispatchQueue.Sync, Queue -> \(queue)"
        case .BarrierSync(let queue): return "DispatchQueue.BarrierSync, Queue -> \(queue)"
        case .Once(let token): return "DispatchQueue.Once, Token -> \(token)"
        }
    }
    
    public var debugDescription: String {
        return description
    }
    
}

{'fraction_non_alphanumeric': 0.08506180599203855, 'fraction_numerical': 0.0035617012361198407, 'mean_word_length': 2.7794932699920825, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 34, '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': '5198991', 'n_tokens_mistral': 2631, 'n_tokens_neox': 2593, 'n_words': 773}