GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Simplify OpenSslCachingKeyMaterialProvider and use lock-free cache reads · netty/netty@d811ca4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler/src/main/java/io/netty/handler/ssl
    • OpenSslCachingKeyMaterialProvider.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/OpenSslCachingKeyMaterialProvider.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/OpenSslCachingKeyMaterialProvider.java
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
* {@link OpenSslKeyMaterialProvider} that will cache the {@link OpenSslKeyMaterial} to reduce the overhead
2626
* of parsing the chain and the key for generation of the material.
2727
* <p>
28-
* Cache reads are lock-free ({@link ConcurrentHashMap#get} + {@code retain()});
29-
* if a concurrent eviction releases the material in between, {@code retain()}
30-
* detects the dead reference count and the read falls back to a cache miss.
31-
* Mutations (insert, evict, destroy) use {@link ConcurrentHashMap#compute} /
32-
* {@link ConcurrentHashMap#computeIfPresent} for atomicity.
28+
* Cache reads are lock-free ({@link ConcurrentHashMap#get} + {@code retain()}).
29+
* A concurrent eviction is safe: either {@code retain()} increments the reference count
30+
* first and the caller keeps a valid reference, or the eviction releases first and
31+
* {@code retain()} detects the dead count, falling back to a cache miss.
32+
* Inserts and removals adjust the reference count atomically with the map operation
33+
* via {@link ConcurrentHashMap#compute} / {@link ConcurrentHashMap#computeIfPresent}.
3334
*/
3435
final class OpenSslCachingKeyMaterialProvider extends OpenSslKeyMaterialProvider {
3536

@@ -60,7 +61,8 @@ private OpenSslKeyMaterial getAndRetain(String alias) {
6061
}
6162

6263
/**
63-
* Atomically inserts material if absent, or retains the existing entry.
64+
* Inserts material if absent, or retains the existing entry if another thread inserted first.
65+
* The returned material is always retained for the caller.
6466
*/
6567
private OpenSslKeyMaterial putIfAbsentAndRetain(String alias, OpenSslKeyMaterial material) {
6668
return cache.compute(alias, (k, existing) -> {
@@ -74,7 +76,8 @@ private OpenSslKeyMaterial putIfAbsentAndRetain(String alias, OpenSslKeyMaterial
7476
}
7577

7678
/**
77-
* Atomically removes and releases the entry for the given alias.
79+
* Removes and releases the entry for the given alias under the bucket lock,
80+
* preventing concurrent {@code retain()} from succeeding on a dead entry.
7881
*/
7982
private void removeAndRelease(String alias) {
8083
cache.computeIfPresent(alias, (k, v) -> {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.