Skip to content

Commit aeb7839

Browse files
committed
Reduce volatile reads in Metadata.LazyValue#toBytes
Fix double-checked locking idiom and reduce volatile reads in Metadata.LazyValue#toBytes.
1 parent 76a631b commit aeb7839

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

api/src/main/java/io/grpc/Metadata.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,12 @@ InputStream toStream() {
936936
}
937937

938938
byte[] toBytes() {
939+
byte[] serialized = this.serialized;
939940
if (serialized == null) {
940941
synchronized (this) {
942+
serialized = this.serialized;
941943
if (serialized == null) {
942-
serialized = streamToBytes(toStream());
944+
this.serialized = serialized = streamToBytes(toStream());
943945
}
944946
}
945947
}

0 commit comments

Comments
 (0)