Skip to content

Commit

Permalink
Add workaround to let the sleep work correctly in windows too. See ne…
Browse files Browse the repository at this point in the history
…tty#356

Conflicts:

	common/src/main/java/io/netty/util/HashedWheelTimer.java
	common/src/main/java/io/netty/util/internal/DetectionUtil.java
  • Loading branch information
normanmaurer authored and trustin committed May 31, 2012
1 parent f6f246c commit 59b5c3a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion common/src/main/java/io/netty/util/HashedWheelTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.util.internal.DetectionUtil;
import io.netty.util.internal.ReusableIterator;
import io.netty.util.internal.SharedResourceMisuseDetector;

Expand Down Expand Up @@ -442,7 +443,16 @@ private long waitForNextTick() {

for (;;) {
final long currentTime = System.currentTimeMillis();
final long sleepTime = tickDuration * tick - (currentTime - startTime);
long sleepTime = tickDuration * tick - (currentTime - startTime);

// Check if we run on windows, as if thats the case we will need
// to round the sleepTime as workaround for a bug that only affect
// the JVM if it runs on windows.
//
// See https://github.com/netty/netty/issues/356
if (DetectionUtil.isWindows()) {
sleepTime = sleepTime / 10 * 10;
}

if (sleepTime <= 0) {
break;
Expand Down
14 changes: 14 additions & 0 deletions common/src/main/java/io/netty/util/internal/DetectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ public final class DetectionUtil {

private static final int JAVA_VERSION = javaVersion0();
private static final boolean HAS_UNSAFE = hasUnsafe(AtomicInteger.class.getClassLoader());
private static final boolean IS_WINDOWS;

static {
String os = System.getProperty("os.name").toLowerCase();
// windows
IS_WINDOWS = os.indexOf("win") >= 0;
}

/**
* Return <code>true</code> if the JVM is running on Windows
*/
public static boolean isWindows() {
return IS_WINDOWS;
}

public static boolean hasUnsafe() {
return HAS_UNSAFE;
Expand Down

0 comments on commit 59b5c3a

Please sign in to comment.