Skip to content

Rework synchronization in ProtobufMapper #484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.concurrent.locks.ReentrantLock;

import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.core.type.TypeReference;
Expand Down Expand Up @@ -42,7 +43,10 @@ public Builder(ProtobufMapper m) {
*
* @since 2.9
*/
protected DescriptorLoader _descriptorLoader;
protected volatile DescriptorLoader _descriptorLoader;

// @since 2.18
private final ReentrantLock _descriptorLock = new ReentrantLock();

/*
/**********************************************************
Expand Down Expand Up @@ -192,11 +196,19 @@ public FileDescriptorSet loadDescriptorSet(InputStream src) throws IOException {
*
* @since 2.9
*/
public synchronized DescriptorLoader descriptorLoader() throws IOException
public DescriptorLoader descriptorLoader() throws IOException
{
DescriptorLoader l = _descriptorLoader;
if (l == null) {
_descriptorLoader = l = DescriptorLoader.construct(this);
_descriptorLock.lock();
try {
l = _descriptorLoader;
if (l == null) {
_descriptorLoader = l = DescriptorLoader.construct(this);
}
} finally {
_descriptorLock.unlock();
}
}
return l;
}
Expand Down
4 changes: 4 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,7 @@ Thomas de Lange (@thomasdelange5)
* Contributed fix for #428: (ion) `IonParser.getIntValue()` fails or does not handle
value overflow checks
(2.17.0)

PJ Fanning (pjfanning@github)
* Contributed #484: Rework synchronization in `ProtobufMapper`
(2.18.0)
3 changes: 2 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Active maintainers:

2.18.0 (not yet released)

No changes since 2.17.
#484: (protobuf) Rework synchronization in `ProtobufMapper`
(contributed by @pjfanning)

2.17.0 (12-Mar-2024)

Expand Down