Skip to content

Commit

Permalink
Rework synchronization in ProtobufMapper (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning authored Apr 7, 2024
1 parent b83b16b commit 11e4b1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit 11e4b1f

Please sign in to comment.