Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift5 #2

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Atomic.podspec
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
Pod::Spec.new do |s|
s.name = 'Atomic'
s.version = '1.0.3'
s.version = '1.1.0'
s.license = 'MIT'
s.summary = 'Atomic is a fast, safe way to make values atomic (thread-safe).'
s.homepage = 'https://github.com/Adlai-Holler/Atomic'
s.social_media_url = 'http://twitter.com/adlaih'
s.authors = { 'Adlai Holler' => '[email protected]' }
s.source = { :git => 'https://github.com/Adlai-Holler/Atomic.git', :tag => 'v1.0.3' }
s.source = { :git => 'https://github.com/Adlai-Holler/Atomic.git', :tag => 'v1.1.0' }

s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'

s.source_files = 'Atomic/*.swift'
s.swift_version = '5.0'

s.requires_arc = true
end
30 changes: 29 additions & 1 deletion Atomic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "Adlai Holler";
TargetAttributes = {
CC6035571C136EE4003ED664 = {
Expand All @@ -204,6 +204,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = CC60354E1C136EE4003ED664;
Expand Down Expand Up @@ -284,17 +285,28 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand Down Expand Up @@ -322,6 +334,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand All @@ -332,17 +345,28 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -362,6 +386,8 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -373,6 +399,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand All @@ -391,6 +418,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
Expand Down
2 changes: 1 addition & 1 deletion Atomic.xcodeproj/xcshareddata/xcschemes/Atomic.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
6 changes: 3 additions & 3 deletions Atomic/Atomic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public final class Atomic<Value> {
/// Atomically replaces the contents of the variable.
///
/// Returns the old value.
public func swap(newValue: Value) -> Value {
@discardableResult public func swap(_ newValue: Value) -> Value {
return modify { _ in newValue }
}

/// Atomically modifies the variable.
///
/// Returns the old value.
public func modify(@noescape action: (Value) throws -> Value) rethrows -> Value {
@discardableResult public func modify(action: (Value) throws -> Value) rethrows -> Value {
return try lock.withCriticalScope {
let oldValue = _value
_value = try action(_value)
Expand All @@ -56,7 +56,7 @@ public final class Atomic<Value> {
/// variable.
///
/// Returns the result of the action.
public func withValue<Result>(@noescape action: (Value) throws -> Result) rethrows -> Result {
public func withValue<Result>(action: (Value) throws -> Result) rethrows -> Result {
return try lock.withCriticalScope {
try action(_value)
}
Expand Down
4 changes: 2 additions & 2 deletions Atomic/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ final public class Lock {
}

extension Lock {
public func withCriticalScope<Result>(@noescape body: () throws -> Result) rethrows -> Result {
public func withCriticalScope<Result>(body: () throws -> Result) rethrows -> Result {
lock()
defer { unlock() }
return try body()
}
}
}
18 changes: 9 additions & 9 deletions AtomicTests/AtomicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ class AtomicTests: XCTestCase {

func testHighlyContestedLocking() {
let contestedAtomic = Atomic(0)
let concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let dispatchGroup = dispatch_group_create()
let concurrentQueue = DispatchQueue.global()
let dispatchGroup = DispatchGroup()
let count = 100_000
for _ in 0..<count {
dispatch_group_enter(dispatchGroup)
dispatch_async(concurrentQueue) {
dispatchGroup.enter()
concurrentQueue.async() {
contestedAtomic.modify { $0 + 1 }
dispatch_group_leave(dispatchGroup)
dispatchGroup.leave()
}
}
let expectation = expectationWithDescription("Dispatch Group Completion")
dispatch_group_notify(dispatchGroup, concurrentQueue) {
expectation.fulfill()
let aExpectation = expectation(description: "Dispatch Group Completion")
dispatchGroup.notify(queue: concurrentQueue) {
aExpectation.fulfill()
}

waitForExpectationsWithTimeout(10, handler: nil)
waitForExpectations(timeout: 10, handler: nil)

XCTAssertEqual(contestedAtomic._value, count)
}
Expand Down