]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scenery/FGTileLoader.cxx
Tweaks to the tile pager so it waits for a signal from the main thread before
[flightgear.git] / src / Scenery / FGTileLoader.cxx
index 5123953e61f45d94b03dce1559ecadb256dc8bcf..3465e0f2bf110daa9e0040ae705d36bc73a5bf7b 100644 (file)
@@ -50,7 +50,7 @@ FGTileLoader::~FGTileLoader()
 {
 #ifdef ENABLE_THREADS
     // Wake up its time to die.
-    cond.broadcast();
+    queue_cond.broadcast();
 
     for (int i = 0; i < MAX_THREADS; ++i)
     {
@@ -86,13 +86,27 @@ FGTileLoader::add( FGTileEntry* tile )
     mutex.lock();
     tile_queue.push( tile );
     // Signal waiting working threads.
-    cond.signal();
+    queue_cond.signal();
     mutex.unlock();
 #else
     tile->load( tile_path, true );
 #endif // ENABLE_THREADS
 }
 
+/**
+ * 
+ */
+void
+FGTileLoader::update()
+{
+#ifdef ENABLE_THREADS
+    mutex.lock();
+    frame_cond.signal();
+    mutex.unlock();
+#endif // ENABLE_THREADS
+}
+
+
 #ifdef ENABLE_THREADS
 /**
  * 
@@ -106,7 +120,7 @@ FGTileLoader::LoaderThread::run()
        loader->mutex.lock();
        while (loader->empty())
        {
-           loader->cond.wait( loader->mutex );
+           loader->queue_cond.wait( loader->mutex );
        }
 
        // Have we been canceled - exits if yes.
@@ -117,6 +131,10 @@ FGTileLoader::LoaderThread::run()
            pthread_exit( PTHREAD_CANCELED );
        }
 
+        // Wait for the next frame signal before we load a tile from the queue
+        // Note that loader->mutex is already locked at this point.
+        loader->frame_cond.wait( loader->mutex );
+
        // Grab the tile to load and release the mutex.
        FGTileEntry* tile = loader->tile_queue.front();
        loader->tile_queue.pop();