From f5b90eec8f7b481962ed835a7b4f08f418fe26db Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sun, 28 Feb 2016 14:11:16 +0100 Subject: [PATCH] Make GFilename::is_fits thread safe (#1717). --- ChangeLog | 3 ++- NEWS | 5 ++++- src/support/GFilename.cpp | 19 ++++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1240a46..115d362 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2016-02-25 Juergen Knoedlseder +2016-02-28 Juergen Knoedlseder * Version 1.1.0 released ========================= + Make GFilename::is_fits thread safe (#1717). Revise GTime operators (#1714) Add GSkyMap::publish() method to publish map on VO Hub (#1710) Add GVOClient::publish() method to publish a FITS HDU (#1710) diff --git a/NEWS b/NEWS index 3a813ba..5758b13 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0 Author(s) : Juergen Knoedlseder -25 February 2016 +28 February 2016 1. Introduction @@ -196,6 +196,9 @@ the access protocol (e.g. http, ftp, file) of the file name, the method path() returns the path of th file name, and the method file() returns the file name without the path. +Put FITS access in a critical OMP zone to make GFilename::is_fits() thread +safe (#1717). + 14. XML module -------------- diff --git a/src/support/GFilename.cpp b/src/support/GFilename.cpp index e907267..3b8c936 100644 --- a/src/support/GFilename.cpp +++ b/src/support/GFilename.cpp @@ -253,7 +253,7 @@ bool GFilename::exists(void) const * @return True if file is a FITS file. * * Test if the file or a compressed version of the file (with a .gz, .Z, .z, - * or .zip extension) is a FITS file. + * or .zip extension) is a FITS file. This method is thread safe. ***************************************************************************/ bool GFilename::is_fits(void) const { @@ -261,14 +261,19 @@ bool GFilename::is_fits(void) const bool is_fits = false; // Check now for a FITS file. This works only if cfitsio is available. + // Put the code into a critical zone as it might be called from within + // a parallelized thread. #if defined(HAVE_LIBCFITSIO) - int status = 0; - fitsfile* fptr = NULL; - status = ffopen(&fptr, url().c_str(), 0, &status); - if (status == 0) { - is_fits = true; + #pragma omp critical + { + int status = 0; + fitsfile* fptr = NULL; + status = ffopen(&fptr, url().c_str(), 0, &status); + if (status == 0) { + is_fits = true; + } + ffclos(fptr, &status); } - ffclos(fptr, &status); #endif // Return result -- libgit2 0.21.4