-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Synchronize evaluateGroupCached to avoid concurrent access to cache (#…
…2980) With this change, we synchronize evaluations of the same terminal task. This isn't necessarily needed for normal Mill executions, but in a BSP context, where multiple requests where handled concurrently in the same Mill instance, evaluating the same task concurrently can happen. We don't synchronize multiple Mill-instances (e.g. run in two shells) or multiple evaluator-instances (which should have different `out`-dirs anyway). Fix: #2818 Pull request: #2980
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package mill.eval | ||
|
||
private class KeyLock[K]() { | ||
private[this] val lockKeys = new java.util.HashSet[K]() | ||
|
||
def lock(key: K, onCollision: Option[() => Unit] = None): AutoCloseable = { | ||
lockKeys.synchronized { | ||
var shown = false | ||
while (!lockKeys.add(key)) { | ||
if (!shown) { | ||
onCollision.foreach(_()) | ||
shown = true | ||
} | ||
lockKeys.wait(); | ||
} | ||
} | ||
() => unlock(key) | ||
} | ||
|
||
private def unlock(key: K): Unit = { | ||
lockKeys.synchronized { | ||
lockKeys.remove(key) | ||
lockKeys.notifyAll() | ||
} | ||
} | ||
} |