<commit_before>//
// SynchronizationPrimitives.swift
// SwiftTaskLibrary
//
// Created by <NAME> on 18/06/2016.
// Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

/// Marks the block as a critical section by obtaining the mutual-exclusion lock for a given object.
public func task_lock(_ lock: AnyObject, closure: () -> Void) {
    objc_sync_enter(lock)
    closure()
    objc_sync_exit(lock)
}

/// Marks the block as a critical section by obtaining the mutual-exclusion lock for a given object.
public func task_trylock(_ lock: AnyObject, closure: () throws -> ()) throws {
    objc_sync_enter(lock)
    do {
        try closure()
        objc_sync_exit(lock)
    }
    catch let error as NSError {
        objc_sync_exit(lock)
        throw error
    }
}
<commit_msg>Added return type for the task_lock<commit_after>//
// SynchronizationPrimitives.swift
// SwiftTaskLibrary
//
// Created by <NAME> on 18/06/2016.
// Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation

/// Marks the block as a critical section by obtaining the mutual-exclusion lock for a given object.
public func task_lock<T>(_ lock: AnyObject, closure: () -> T) -> T {
    defer {
        objc_sync_exit(lock)
    }
    objc_sync_enter(lock)
    return closure()
}

/// Marks the block as a critical section by obtaining the mutual-exclusion lock for a given object.
public func task_trylock<T>(_ lock: AnyObject, closure: () throws -> T) throws -> T {
    defer {
        objc_sync_exit(lock)
    }
    objc_sync_enter(lock)
    return try closure()
}

{'fraction_non_alphanumeric': 0.10492642354446577, 'fraction_numerical': 0.015355086372360844, 'mean_word_length': 3.0, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '2883145', 'n_tokens_mistral': 507, 'n_tokens_neox': 472, 'n_words': 163}