A long, long time ago, a bug was inadvertently introduced into the threaded
metar fetcher. Effectively this caused the metar thread and the main thread to both attempt to fetch weather data. This could lead to long pauses when the main thread decided to fetch the weather, and introduced a race condition that could cause a segfault/crash. Investigating this issue, I discovered that even longer ago, someone confused #defines and #ifdef symbols with C/C++ variables. If I #define XYZ 0 it is defined so #ifdef XYZ is true, not false like a variable. Our thread detection made this mistake and there were follow up patches to work around it. So I fixed the configure script (ahhh, reading the autoconf manual is highly recommended excercise for people editing the configure.ac file.) I also discovered that we were hardwiring with_threads=yes with no way via configure options to disable threads from the build so I fixed that. Then I patched up the #ifdef's scattered through the code to match the configure script changes, oh and by the way, I stumbled upon a past typo that led to the race condition in the metar fetching thread and fixed that.
This commit is contained in:
parent
4443267e4e
commit
e807c7f95c
6 changed files with 22 additions and 22 deletions
|
@ -330,7 +330,7 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
|
|||
_dt( 0.0 ),
|
||||
_error_dt( 0.0 )
|
||||
{
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
thread = new MetarThread(this);
|
||||
thread->start( 1 );
|
||||
#endif // ENABLE_THREADS
|
||||
|
@ -338,7 +338,7 @@ FGMetarEnvironmentCtrl::FGMetarEnvironmentCtrl ()
|
|||
|
||||
FGMetarEnvironmentCtrl::~FGMetarEnvironmentCtrl ()
|
||||
{
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
thread->cancel();
|
||||
thread->join();
|
||||
#endif // ENABLE_THREADS
|
||||
|
@ -491,7 +491,7 @@ FGMetarEnvironmentCtrl::update(double delta_time_sec)
|
|||
}
|
||||
}
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if !defined(ENABLE_THREADS)
|
||||
// No loader thread running so manually fetch the data
|
||||
string id = "";
|
||||
while ( !request_queue.empty() ) {
|
||||
|
@ -582,7 +582,7 @@ FGMetarEnvironmentCtrl::fetch_data( const string &icao )
|
|||
} catch (const sg_io_exception& e) {
|
||||
SG_LOG( SG_GENERAL, SG_WARN, "Error fetching live weather data: "
|
||||
<< e.getFormattedMessage().c_str() );
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
if (_error_count++ >= 3) {
|
||||
SG_LOG( SG_GENERAL, SG_WARN, "Stop fetching data permanently.");
|
||||
thread->cancel();
|
||||
|
@ -701,7 +701,7 @@ FGMetarEnvironmentCtrl::update_metar_properties( const FGMetar *m )
|
|||
}
|
||||
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <simgear/structure/subsystem_mgr.hxx>
|
||||
#include <simgear/environment/metar.hxx>
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
# include <simgear/threads/SGThread.hxx>
|
||||
# include <simgear/threads/SGQueue.hxx>
|
||||
#endif
|
||||
|
@ -185,7 +185,7 @@ private:
|
|||
|
||||
private:
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
/**
|
||||
* FIFO queue which holds a pointer to the fetched metar data.
|
||||
*/
|
||||
|
@ -207,7 +207,7 @@ private:
|
|||
queue < FGMetarResult > result_queue;
|
||||
#endif
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
/**
|
||||
* This class represents the thread of execution responsible for
|
||||
* fetching the metar data.
|
||||
|
|
|
@ -41,7 +41,7 @@ extern ssgBranch *ground;
|
|||
*/
|
||||
FGTileLoader::FGTileLoader()
|
||||
{
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
// Create and start the loader threads.
|
||||
for (int i = 0; i < MAX_THREADS; ++i)
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ FGTileLoader::FGTileLoader()
|
|||
*/
|
||||
FGTileLoader::~FGTileLoader()
|
||||
{
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
// Wake up its time to die.
|
||||
// queue_cond.broadcast();
|
||||
|
||||
|
@ -121,7 +121,7 @@ void
|
|||
FGTileLoader::update()
|
||||
{
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
// send a signal to the pager thread that it is allowed to load
|
||||
// another tile
|
||||
mutex.lock();
|
||||
|
@ -155,7 +155,7 @@ FGTileLoader::update()
|
|||
}
|
||||
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <simgear/bucket/newbucket.hxx>
|
||||
#include <simgear/misc/sg_path.hxx>
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
# include <simgear/threads/SGThread.hxx>
|
||||
# include <simgear/threads/SGQueue.hxx>
|
||||
#else
|
||||
|
@ -97,7 +97,7 @@ private:
|
|||
|
||||
private:
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
/**
|
||||
* FIFO queue of tiles to load from data files.
|
||||
*/
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
*/
|
||||
string_list tile_path;
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
/**
|
||||
* Maximum number of threads to create for loading tiles.
|
||||
*/
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
|
||||
#define TEST_LAST_HIT_CACHE
|
||||
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
SGLockedQueue<FGTileEntry *> FGTileMgr::attach_queue;
|
||||
SGLockedQueue<FGDeferredModel *> FGTileMgr::model_queue;
|
||||
#else
|
||||
|
@ -92,7 +92,7 @@ int FGTileMgr::init() {
|
|||
}
|
||||
|
||||
while ( ! model_queue.empty() ) {
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
FGDeferredModel* dm = model_queue.pop();
|
||||
#else
|
||||
FGDeferredModel* dm = model_queue.front();
|
||||
|
@ -299,7 +299,7 @@ void FGTileMgr::update_queues()
|
|||
|
||||
// cout << "loading next model ..." << endl;
|
||||
// load the next tile in the queue
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
FGDeferredModel* dm = model_queue.pop();
|
||||
#else
|
||||
FGDeferredModel* dm = model_queue.front();
|
||||
|
@ -337,7 +337,7 @@ void FGTileMgr::update_queues()
|
|||
loader.update();
|
||||
|
||||
if ( !attach_queue.empty() ) {
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
FGTileEntry* e = attach_queue.pop();
|
||||
#else
|
||||
FGTileEntry* e = attach_queue.front();
|
||||
|
@ -364,7 +364,7 @@ void FGTileMgr::update_queues()
|
|||
// get real serious and agressively free up some tiles so
|
||||
// we don't explode our memory usage.
|
||||
|
||||
SG_LOG( SG_TERRAIN, SG_WARN,
|
||||
SG_LOG( SG_TERRAIN, SG_ALERT,
|
||||
"Warning: catching up on tile delete queue" );
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include <queue>
|
||||
|
||||
#include <simgear/bucket/newbucket.hxx>
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
# include <simgear/threads/SGQueue.hxx>
|
||||
#endif // ENABLE_THREADS
|
||||
|
||||
|
@ -118,7 +118,7 @@ private:
|
|||
* model_queue is the set of models that need to be loaded by the
|
||||
* primary render thread.
|
||||
*/
|
||||
#if defined(ENABLE_THREADS) && ENABLE_THREADS
|
||||
#if defined(ENABLE_THREADS)
|
||||
static SGLockedQueue<FGTileEntry *> attach_queue;
|
||||
static SGLockedQueue<FGDeferredModel *> model_queue;
|
||||
#else
|
||||
|
|
Loading…
Add table
Reference in a new issue