/// <summary> /// If a latch is currently installed for the given (or any colliding) identifier, then it will be waited upon and /// {@code null} will be returned. /// /// Otherwise, if there is currently no latch installed for the given identifier, then one will be created and /// installed, and that latch will be returned. Once the page fault has been completed, the returned latch must be /// released. Releasing the latch will unblock all threads that are waiting upon it, and the latch will be /// atomically uninstalled. /// </summary> internal Latch TakeOrAwaitLatch(long identifier) { int index = index(identifier); Latch latch = GetLatch(index); while (latch == null) { latch = new Latch(); if (CompareAndSetLatch(index, null, latch)) { latch.LatchMap = this; latch.Index = index; return(latch); } latch = GetLatch(index); } latch.Await(); return(null); }