-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
157 additions
and
51 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
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
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
*/ | ||
package io.vertx.core.impl; | ||
|
||
import io.vertx.core.spi.context.ContextKey; | ||
import io.vertx.core.spi.context.locals.ContextKey; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
|
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
78 changes: 78 additions & 0 deletions
78
src/main/java/io/vertx/core/spi/context/locals/AccessMode.java
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,78 @@ | ||
/* | ||
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.core.spi.context.locals; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.VarHandle; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Defines the access mode of a context locals | ||
*/ | ||
public interface AccessMode { | ||
|
||
/** | ||
* This access mode provides concurrent access to context locals with thread safety and atomicity. | ||
*/ | ||
AccessMode CONCURRENT = new AccessMode() { | ||
|
||
private final VarHandle LOCALS_UPDATER = MethodHandles.arrayElementVarHandle(Object[].class); | ||
|
||
@Override | ||
public Object get(Object[] locals, int idx) { | ||
return LOCALS_UPDATER.getVolatile(locals, idx); | ||
} | ||
|
||
@Override | ||
public void put(Object[] locals, int idx, Object value) { | ||
LOCALS_UPDATER.setRelease(locals, idx, value); | ||
} | ||
|
||
@Override | ||
public Object getOrCreate(Object[] locals, int index, Supplier<Object> initialValueSupplier) { | ||
Object res; | ||
while (true) { | ||
res = LOCALS_UPDATER.getVolatile(locals, index); | ||
if (res != null) { | ||
break; | ||
} | ||
Object initial = initialValueSupplier.get(); | ||
if (initial == null) { | ||
throw new IllegalStateException(); | ||
} | ||
if (LOCALS_UPDATER.compareAndSet(locals, index, null, initial)) { | ||
res = initial; | ||
break; | ||
} | ||
} | ||
return res; | ||
} | ||
}; | ||
|
||
/** | ||
* Return the object at index {@code idx} in the {@code locals} array. | ||
* @param locals the array | ||
* @param idx the index | ||
* @return the object at {@code index} | ||
*/ | ||
Object get(Object[] locals, int idx); | ||
|
||
/** | ||
* Put {@code value} in the {@code locals} array at index {@code idx} | ||
* @param locals the array | ||
* @param idx the index | ||
* @param value the value | ||
*/ | ||
void put(Object[] locals, int idx, Object value); | ||
|
||
Object getOrCreate(Object[] locals, int index, Supplier<Object> initialValueSupplier); | ||
|
||
} |
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
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
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
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