#include <Main/globals.hxx>
#include "FGTileLoader.hxx"
#include "tileentry.hxx"
+#include "tilemgr.hxx"
+
+extern ssgBranch *terrain;
+extern ssgBranch *ground;
/**
*
{
#ifdef ENABLE_THREADS
// Wake up its time to die.
- queue_cond.broadcast();
+ // queue_cond.broadcast();
for (int i = 0; i < MAX_THREADS; ++i)
{
beenhere = true;
}
-#ifdef ENABLE_THREADS
- mutex.lock();
- tile_queue.push( tile );
- // Signal waiting working threads.
- queue_cond.signal();
- mutex.unlock();
-#else
- tile->load( tile_path, true );
-#endif // ENABLE_THREADS
+ tile_load_queue.push( tile );
+}
+
+/**
+ *
+ */
+void
+FGTileLoader::remove( FGTileEntry* tile )
+{
+ tile_free_queue.push( tile );
}
/**
FGTileLoader::update()
{
#ifdef ENABLE_THREADS
+ // send a signal to the pager thread that it is allowed to load
+ // another tile
mutex.lock();
frame_cond.signal();
mutex.unlock();
+#else
+ if ( !tile_load_queue.empty() ) {
+ cout << "loading next tile ..." << endl;
+ // load the next tile in the queue
+ FGTileEntry* tile = tile_load_queue.front();
+ tile_load_queue.pop();
+ tile->load( tile_path, true );
+ FGTileMgr::loaded( tile );
+ }
+
+ if ( !tile_free_queue.empty() ) {
+ cout << "freeing next tile ..." << endl;
+ // free the next tile in the queue
+ FGTileEntry* tile = tile_free_queue.front();
+ tile_free_queue.pop();
+ tile->free_tile();
+ delete tile;
+ }
+
#endif // ENABLE_THREADS
}
pthread_cleanup_push( cleanup_handler, loader );
while ( true ) {
// Wait for a load request to be placed in the queue.
- loader->mutex.lock();
- while (loader->empty())
- {
- loader->queue_cond.wait( loader->mutex );
- }
-
- // Have we been canceled - exits if yes.
- //pthread_testcancel();
- if (loader->empty())
- {
- loader->mutex.unlock();
- pthread_exit( PTHREAD_CANCELED );
- }
+ FGTileEntry* tile = loader->tile_load_queue.pop();
// 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->mutex.lock();
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();
- loader->mutex.unlock();
+ loader->mutex.unlock();
set_cancel( SGThread::CANCEL_DISABLE );
tile->load( loader->tile_path, true );
set_cancel( SGThread::CANCEL_DEFERRED );
+
+ FGTileMgr::ready_to_attach( tile );
+
+ // Handle and pending removals
+ while ( !loader->tile_free_queue.empty() ) {
+ cout << "freeing next tile ..." << endl;
+ // free the next tile in the queue
+ FGTileEntry* tile = loader->tile_free_queue.pop();
+ tile->free_tile();
+ delete tile;
+ }
}
pthread_cleanup_pop(1);
}