Skip to content
Merged
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
8 changes: 4 additions & 4 deletions Concurrency.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
413AD8C020AF73AB00AD7F36 /* PBXContainerItemProxy */ = {
412CDD2D20B88EAB00AF5890 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
proxyType = 1;
remoteGlobalIDString = "Concurrency::Concurrency";
remoteInfo = Concurrency;
};
413AD8C120AF73AB00AD7F36 /* PBXContainerItemProxy */ = {
412CDD2E20B88EAB00AF5890 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = OBJ_1 /* Project object */;
proxyType = 1;
Expand Down Expand Up @@ -258,12 +258,12 @@
OBJ_42 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = "Concurrency::ConcurrencyTests" /* ConcurrencyTests */;
targetProxy = 413AD8C120AF73AB00AD7F36 /* PBXContainerItemProxy */;
targetProxy = 412CDD2E20B88EAB00AF5890 /* PBXContainerItemProxy */;
};
OBJ_54 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = "Concurrency::Concurrency" /* Concurrency */;
targetProxy = 413AD8C020AF73AB00AD7F36 /* PBXContainerItemProxy */;
targetProxy = 412CDD2D20B88EAB00AF5890 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

Expand Down
12 changes: 9 additions & 3 deletions Sources/Concurrency/CountDownLatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ public class CountDownLatch {
}

condition.lock()
defer {
condition.unlock()
}
// Check count again after acquiring the lock, before entering waiting. This ensures the caller
// does not enter waiting after the last counting down occurs.
if conditionCount.value > 0 {
return condition.wait(until: deadline)
// NSCondition must be run in a loop, since it can wake up randomly without any siganling.
while conditionCount.value > 0 {
let result = condition.wait(until: deadline)
if !result || Date() > deadline {
return false
}
}
condition.unlock()
return true
}

Expand Down