//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id$
FGMetarEnvironmentCtrl::~FGMetarEnvironmentCtrl ()
{
#if defined(ENABLE_THREADS)
- thread->cancel();
- thread->join();
+ thread_stop();
#endif // ENABLE_THREADS
delete env;
#if defined(ENABLE_THREADS)
if (_error_count++ >= 3) {
SG_LOG( SG_GENERAL, SG_WARN, "Stop fetching data permanently.");
- thread->cancel();
- thread->join();
+ thread_stop();
}
#endif
#if defined(ENABLE_THREADS)
-/**
- * Ensure mutex is unlocked.
- */
void
-metar_cleanup_handler( void* arg )
+FGMetarEnvironmentCtrl::thread_stop()
{
- FGMetarEnvironmentCtrl* fetcher = (FGMetarEnvironmentCtrl*) arg;
- fetcher->mutex.unlock();
+ request_queue.push( string() ); // ask thread to terminate
+ thread->join();
}
-/**
- *
- */
void
FGMetarEnvironmentCtrl::MetarThread::run()
{
- pthread_cleanup_push( metar_cleanup_handler, fetcher );
while ( true )
{
- set_cancel( SGThread::CANCEL_DISABLE );
-
string icao = fetcher->request_queue.pop();
+ if (icao.empty())
+ return;
SG_LOG( SG_GENERAL, SG_INFO, "Thread: fetch metar data = " << icao );
FGMetarResult result = fetcher->fetch_data( icao );
-
- set_cancel( SGThread::CANCEL_DEFERRED );
-
fetcher->result_queue.push( result );
}
- pthread_cleanup_pop(1);
}
#endif // ENABLE_THREADS