Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# * http://www.objc.io/issue-6/travis-ci.html
# * https://github.com/supermarin/xcpretty#usage

osx_image: xcode7.3
osx_image: xcode12.0
language: objective-c
cache: cocoapods
podfile: Example/Podfile
Expand Down
66 changes: 44 additions & 22 deletions Example/HLClock.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
6EA979257ADA19E9278C06C4 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
70B03B0CE5FA7F205F3CB56C /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
9AAC17CE0F36550F9712AFFD /* HLClock.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HLClock.podspec; path = ../HLClock.podspec; sourceTree = "<group>"; };
9AAC17CE0F36550F9712AFFD /* HLClock.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = HLClock.podspec; path = ../HLClock.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
9F71206535A4DD716C9228A8 /* Pods-HLClock_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HLClock_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-HLClock_Tests/Pods-HLClock_Tests.debug.xcconfig"; sourceTree = "<group>"; };
AEADEF38E5170EE4EC8603E2 /* Pods-HLClock_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-HLClock_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-HLClock_Tests/Pods-HLClock_Tests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -110,7 +110,6 @@
607FACE21AFB9204008FA782 /* Frameworks */,
607FACE31AFB9204008FA782 /* Resources */,
CE57DF5D349E513F7FE1BFCE /* [CP] Embed Pods Frameworks */,
B84BAF3347D210C9F811BFF6 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -128,7 +127,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0720;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 1150;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACE41AFB9204008FA782 = {
Expand All @@ -142,6 +141,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -172,28 +172,16 @@
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-HLClock_Tests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
B84BAF3347D210C9F811BFF6 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-HLClock_Tests/Pods-HLClock_Tests-resources.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
CE57DF5D349E513F7FE1BFCE /* [CP] Embed Pods Frameworks */ = {
Expand All @@ -202,13 +190,20 @@
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-HLClock_Tests/Pods-HLClock_Tests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/HLClock/HLClock.framework",
"${BUILT_PRODUCTS_DIR}/Nimble/Nimble.framework",
"${BUILT_PRODUCTS_DIR}/Quick/Quick.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/HLClock.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Nimble.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Quick.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-HLClock_Tests/Pods-HLClock_Tests-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-HLClock_Tests/Pods-HLClock_Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand All @@ -229,17 +224,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 @@ -262,29 +268,41 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
607FACEE1AFB9204008FA782 /* Release */ = {
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 @@ -300,9 +318,11 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -317,6 +337,7 @@
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -329,6 +350,7 @@
buildSettings = {
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "1150"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -41,6 +41,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "HLClock_Example.app"
BlueprintName = "HLClock_Example"
ReferencedContainer = "container:HLClock.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -53,17 +62,6 @@
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "HLClock_Example.app"
BlueprintName = "HLClock_Example"
ReferencedContainer = "container:HLClock.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -85,8 +83,6 @@
ReferencedContainer = "container:HLClock.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use_frameworks!
target 'HLClock_Tests' do
pod 'HLClock', :path => '../'

pod 'Quick', '~> 0.8'
pod 'Nimble', '~> 3.0'
pod 'Quick', '~> 3.0.0'
pod 'Nimble', '~> 8.1.1'
end
6 changes: 4 additions & 2 deletions HLClock.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'HLClock'
s.version = '0.2.0'
s.version = '0.3.0'
s.summary = 'Hybrid Logical Clocks for iOS.'

# This description is used to generate tags and improve search results.
Expand All @@ -29,9 +29,11 @@ See: http://muratbuffalo.blogspot.com/2014/07/hybrid-logical-clocks.html
s.source = { :git => 'https://github.com/opentable/HLClock.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

s.ios.deployment_target = '8.0'
s.ios.deployment_target = '12.0'

s.source_files = 'HLClock/Classes/**/*'

s.swift_version = '5.0'

# s.resource_bundles = {
# 'HLClock' => ['HLClock/Assets/*.png']
Expand Down
14 changes: 7 additions & 7 deletions HLClock/Classes/HLClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
import UIKit

/// Send function as described in Figure 5 of HLC paper
func send<L:IntegerType, C:IntegerType> (j: (l:L, c:C), pt:L) -> (L, C) {
func send<L:FixedWidthInteger, C:FixedWidthInteger> (_ j: (l:L, c:C), pt:L) -> (L, C) {
var j´ = j

j´.l = max(j.l, pt)
Expand All @@ -31,7 +31,7 @@ func send<L:IntegerType, C:IntegerType> (j: (l:L, c:C), pt:L) -> (L, C) {
}

/// Receive function as described in Figure 5 of HLC paper
func recv<L:IntegerType, C:IntegerType> (j: (l:L, c:C), m: (l:L, c:C), pt:L) -> (L, C) {
func recv<L:FixedWidthInteger, C:FixedWidthInteger> (_ j: (l:L, c:C), m: (l:L, c:C), pt:L) -> (L, C) {
var j´ = j

j´.l = max(j.l, m.l, pt)
Expand All @@ -53,12 +53,12 @@ func recv<L:IntegerType, C:IntegerType> (j: (l:L, c:C), m: (l:L, c:C), pt:L) ->
// Pack and Unpack, see HLC paper: '6.2 Compact Timestamping using l and c'

/// Pack l and c into 64bit timestamp
func pack( t: (l:Int64, c:Int64) ) -> Int64 {
func pack(_ t: (l:Int64, c:Int64) ) -> Int64 {
return ceil48(t.l) | t.c
}

/// Unack l and c from 64bit timestamp
func unpack( t: Int64 ) -> (l: Int64, c: Int64) {
func unpack(_ t: Int64 ) -> (l: Int64, c: Int64) {
return (t & ~0xffff, t & 0xffff)
}

Expand All @@ -74,7 +74,7 @@ public class HLClock {
/// Physical time generator
var clock : ()->Int64

public init (clock: ()->Int64 = NetworkTime.global.now) {
public init (clock: @escaping ()->Int64 = NetworkTime.global.now) {
self.clock = clock
}

Expand All @@ -86,6 +86,6 @@ public class HLClock {
/// Update internal state with received message
public func update(m:Int64) -> Int64 {
return swap(&self.j,
f: {j in pack(recv(unpack(j), m: unpack(m), pt: ceil48(self.clock())))})
f: {j in pack(recv(unpack(j), m: unpack(m), pt: ceil48(self.clock())))})
}
}
}
10 changes: 5 additions & 5 deletions HLClock/Classes/Lib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

/// Applies function `f` to Int64 `i` atomically
func swap (inout i: Int64, f: Int64 -> Int64) -> Int64 {
func swap (_ i: inout Int64, f: (Int64) -> Int64) -> Int64 {
while true {
let p = i
if OSAtomicCompareAndSwap64Barrier(p, f(p), &i) {
Expand All @@ -19,16 +19,16 @@ func swap (inout i: Int64, f: Int64 -> Int64) -> Int64 {
}

/// Convert from NSDate instance to integer nanoseconds
func toNanos (t: NSDate) -> Int64 {
func toNanos (_ t: NSDate) -> Int64 {
return Int64(t.timeIntervalSince1970 * 1e9)
}

/// Convert from integer nanoseconds to NSDate instance
func fromNanos (t: Int64) -> NSDate {
func fromNanos (_ t: Int64) -> NSDate {
return NSDate.init(timeIntervalSince1970: Double(t) / 1e9)
}

/// Take ceiling to 48th bit
func ceil48 ( t: Int64 ) -> Int64 {
func ceil48 (_ t: Int64 ) -> Int64 {
return t & ~0xffff | 0x10000
}
}
4 changes: 2 additions & 2 deletions HLClock/Classes/NetworkTime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

public class NetworkTime {
// Create global instance
static let global = NetworkTime()
public static let global = NetworkTime()

/// Physical Time offset in nanoseconds
var offsetNanos : Int64 = 0
Expand All @@ -28,4 +28,4 @@ public class NetworkTime {
return swap(&self.offsetNanos,
f: {current in abs(newOffset - current) >= Int64(1e9) ? newOffset : current})
}
}
}
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ lint:
pod lib lint

test:
set -o pipefail && xcodebuild test -workspace Example/HLClock.xcworkspace -scheme HLClock-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
set -o pipefail && xcodebuild test -workspace Example/HLClock.xcworkspace -scheme HLClock-Example -destination 'platform=iOS Simulator,name=iPhone 8,OS=12.0' ONLY_ACTIVE_ARCH=NO | xcpretty

travis: lint test