Attempt to fix the slow loading problem. Instead of forcing the main thread to wait around

on every call to processWindowMessages, we will simply skip it, if the mutex is already
claimed by the display thread. This should fix slow loading issues seen by some with
the new loading screen.
This commit is contained in:
cpw 2015-05-16 12:55:15 -04:00
parent dca8a4a550
commit 5fe653cf82
2 changed files with 17 additions and 4 deletions

View File

@ -1003,9 +1003,11 @@ public class FMLClientHandler implements IFMLSidedHandler
public void processWindowMessages()
{
// workaround for windows requiring messages being processed on the main thread
if(LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS)
{
Display.processMessages();
}
if (LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_WINDOWS) return;
// If we can't grab the mutex, the update call is blocked, probably in native code, just skip it and carry on
// We'll get another go next time
if (!SplashProgress.mutex.tryAcquire()) return;
Display.processMessages();
SplashProgress.mutex.release();
}
}

View File

@ -13,6 +13,7 @@ import java.lang.Thread.UncaughtExceptionHandler;
import java.nio.IntBuffer;
import java.util.Iterator;
import java.util.Properties;
import java.util.concurrent.Semaphore;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@ -81,6 +82,7 @@ public class SplashProgress
private static int barBorderColor;
private static int barColor;
private static int barBackgroundColor;
static final Semaphore mutex = new Semaphore(1);
private static String getString(String name, String def)
{
@ -297,7 +299,16 @@ public class SplashProgress
glEnd();
glDisable(GL_TEXTURE_2D);
// We use mutex to indicate safely to the main thread that we're taking the display global lock
// So the main thread can skip processing messages while we're updating.
// There are system setups where this call can pause for a while, because the GL implementation
// is trying to impose a framerate or other thing is occurring. Without the mutex, the main
// thread would delay waiting for the same global display lock
mutex.acquireUninterruptibly();
Display.update();
// As soon as we're done, we release the mutex. The other thread can now ping the processmessages
// call as often as it wants until we get get back here again
mutex.release();
if(pause)
{
clearGL();