Coverage Summary for Class: OverflowAvoidingLockSupport (com.google.common.util.concurrent)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| OverflowAvoidingLockSupport | 100% (1/1) | 50% (1/2) | 66.7% (2/3) |
1 /* 2 * Copyright (C) 2020 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.util.concurrent; 16 17 import static java.lang.Math.min; 18 19 import java.util.concurrent.locks.LockSupport; 20 import javax.annotation.CheckForNull; 21 22 /** 23 * Works around an android bug, where parking for more than INT_MAX seconds can produce an abort 24 * signal on 32 bit devices running Android Q. 25 */ 26 @ElementTypesAreNonnullByDefault 27 final class OverflowAvoidingLockSupport { 28 // Represents the max nanoseconds representable on a linux timespec with a 32 bit tv_sec 29 static final long MAX_NANOSECONDS_THRESHOLD = (1L + Integer.MAX_VALUE) * 1_000_000_000L - 1L; 30 31 private OverflowAvoidingLockSupport() {} 32 33 static void parkNanos(@CheckForNull Object blocker, long nanos) { 34 // Even in the extremely unlikely event that a thread unblocks itself early after only 68 years, 35 // this is indistinguishable from a spurious wakeup, which LockSupport allows. 36 LockSupport.parkNanos(blocker, min(nanos, MAX_NANOSECONDS_THRESHOLD)); 37 } 38 }