Skip to content

Commit

Permalink
make MutexLock fimex-internal
Browse files Browse the repository at this point in the history
 * the size of MutexType depends on _OPENMP, so it might be better
   not to let NcmlCDMReader have a member of type "MutexType"

(cherry picked from commit 829eec8)
  • Loading branch information
alexander-buerger-met-no committed Nov 25, 2016
1 parent 3b64e27 commit 009e084
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 23 deletions.
5 changes: 3 additions & 2 deletions include/fimex/NcmlCDMReader.h
Expand Up @@ -30,13 +30,14 @@
#include "fimex/CDMReader.h"
#include "fimex/CDMDataType.h"
#include "fimex/XMLInput.h"
#include "fimex/MutexLock.h"
#include <map>
#include <memory>

namespace MetNoFimex
{
/* forward declarations */
class XMLDoc;
class MutexType;

/**
* The NcmlCDMReader can be used as both standard reader of a data and
Expand Down Expand Up @@ -141,7 +142,7 @@ class NcmlCDMReader: public MetNoFimex::CDMReader

std::string configId;
boost::shared_ptr<XMLDoc> doc;
MutexType mutex_;
std::auto_ptr<MutexType> mutex_;
boost::shared_ptr<CDMReader> dataReader;
/*
* maps containing the changes. The key will reflect
Expand Down
3 changes: 1 addition & 2 deletions src/CDMTimeInterpolator.cc
Expand Up @@ -34,7 +34,7 @@
#include "fimex/Data.h"
#include "fimex/interpolation.h"
#include "fimex/Logger.h"
#include "fimex/MutexLock.h"
#include "fimex/Utils.h"

namespace MetNoFimex
{
Expand Down Expand Up @@ -85,7 +85,6 @@ CDMTimeInterpolator::~CDMTimeInterpolator()
{
}

MutexType staticMutex;
DataPtr CDMTimeInterpolator::getDataSlice(const std::string& varName, size_t unLimDimPos)
{
std::string timeAxis = getTimeAxis(coordSystems_, getCDM(), varName);
Expand Down
2 changes: 1 addition & 1 deletion src/FeltCDMReader2.h
Expand Up @@ -48,7 +48,7 @@
#include "fimex/ReplaceStringObject.h"
#include "fimex/XMLInput.h"
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "fimex/MutexLock.h"
#include "MutexLock.h"


namespace MetNoFelt {
Expand Down
2 changes: 1 addition & 1 deletion src/GribCDMReader.cc
Expand Up @@ -47,7 +47,7 @@
#include <map>
#include <algorithm>
#include <stdexcept>
#include "fimex/MutexLock.h"
#include "MutexLock.h"
#include <boost/math/special_functions/round.hpp>

namespace MetNoFimex
Expand Down
2 changes: 1 addition & 1 deletion src/MetGmCDMReader.cc
Expand Up @@ -25,7 +25,7 @@
#include "fimex/MetGmCDMReader.h"
#undef MIFI_IO_READER_SUPPRESS_DEPRECATED
#include <fimex/CDM.h>
#include "fimex/MutexLock.h"
#include "MutexLock.h"

// private implementation details
#include "./metgm/MetGmCDMReaderImpl.h"
Expand Down
6 changes: 4 additions & 2 deletions include/fimex/MutexLock.h → src/MutexLock.h
Expand Up @@ -29,12 +29,14 @@

#include <boost/noncopyable.hpp>

#ifdef _OPENMP
# include <omp.h>
#endif

namespace MetNoFimex
{


#ifdef _OPENMP
# include <omp.h>
struct MutexType : boost::noncopyable
{
MutexType() {omp_init_lock(&lock_);}
Expand Down
10 changes: 7 additions & 3 deletions src/NcmlCDMReader.cc
Expand Up @@ -25,6 +25,7 @@
*/

#include "fimex/NcmlCDMReader.h"
#include "MutexLock.h"
#include "NcmlAggregationReader.h"
#include "fimex/XMLDoc.h"
#include <libxml/tree.h>
Expand All @@ -50,6 +51,7 @@ static LoggerPtr logger = getLogger("fimex/NcmlCDMReader");

NcmlCDMReader::NcmlCDMReader(const XMLInput& configXML)
: configId(configXML.id())
, mutex_(new MutexType())
{
#ifdef HAVE_NETCDF_H
setConfigDoc(configXML);
Expand Down Expand Up @@ -78,7 +80,9 @@ NcmlCDMReader::NcmlCDMReader(const XMLInput& configXML)
}

NcmlCDMReader::NcmlCDMReader(const boost::shared_ptr<CDMReader> dataReader, const XMLInput& configXML)
: configId(configXML.id()), dataReader(dataReader)
: configId(configXML.id())
, mutex_(new MutexType())
, dataReader(dataReader)
{
setConfigDoc(configXML);
init();
Expand Down Expand Up @@ -475,7 +479,7 @@ void NcmlCDMReader::initAttributeNameChange()

DataPtr NcmlCDMReader::getDataSlice(const std::string& varName, size_t unLimDimPos)
{
ScopedCritical sc(mutex_);
ScopedCritical sc(*mutex_);
LOG4FIMEX(logger, Logger::DEBUG, "getDataSlice(var,unlimDimPos): (" << varName << ", " << unLimDimPos << ")");
// return unchanged data from this CDM
const CDMVariable& variable = cdm_->getVariable(varName);
Expand Down Expand Up @@ -562,7 +566,7 @@ DataPtr NcmlCDMReader::getDataSlice(const std::string& varName, size_t unLimDimP

DataPtr NcmlCDMReader::getDataSlice(const std::string& varName, const SliceBuilder& sb)
{
ScopedCritical sc(mutex_);
ScopedCritical sc(*mutex_);
LOG4FIMEX(logger, Logger::DEBUG, "getDataSlice(var,sb): (" << varName << ", sb)");
// return unchanged data from this CDM
const CDMVariable& variable = cdm_->getVariable(varName);
Expand Down
2 changes: 0 additions & 2 deletions src/NetCDF_CDMWriter.cc
Expand Up @@ -54,8 +54,6 @@ extern "C" {
#include "fimex/NcmlCDMReader.h"
#include "fimex/Data.h"
#include "NetCDF_Utils.h"
#include "fimex/MutexLock.h" // also includes omp.h


namespace MetNoFimex
{
Expand Down
5 changes: 2 additions & 3 deletions src/NetCDF_Utils.cc
Expand Up @@ -25,7 +25,7 @@
#include "fimex/Data.h"
#include "fimex/CDMException.h"
#include "fimex/Logger.h"
#include "fimex/MutexLock.h"
#include "MutexLock.h"
#include <boost/scoped_array.hpp>
#include <functional>
#include <numeric>
Expand Down Expand Up @@ -63,9 +63,8 @@ Nc::~Nc()
}
}

static MutexType mt;
MutexType& Nc::getMutex() {
return mt;
return ncMutex;
}

nc_type cdmDataType2ncType(CDMDataType dt) {
Expand Down
2 changes: 1 addition & 1 deletion src/NetCDF_Utils.h
Expand Up @@ -27,7 +27,7 @@
#include <boost/shared_ptr.hpp>
#include "fimex/CDMDataType.h"
#include "fimex/DataDecl.h"
#include "fimex/MutexLock.h"
#include "MutexLock.h"
extern "C" {
#include "netcdf.h"
}
Expand Down
2 changes: 1 addition & 1 deletion src/Null_CDMWriter.cc
Expand Up @@ -27,7 +27,7 @@
#include "fimex/CDMDataType.h"
#include "fimex/Utils.h"
#include "fimex/Data.h"
#include "fimex/MutexLock.h"
#include "MutexLock.h"
#include "fimex/Logger.h"

#include "../config.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ProradXMLCDMReader.cc
Expand Up @@ -24,7 +24,7 @@
* Author: Heiko Klein
*/
#include <ProradXMLCDMReader.h>
#include "fimex/MutexLock.h"
#include "MutexLock.h"
#include "fimex/Logger.h"
#include "fimex/CDM.h"
#include "fimex/coordSys/LatitudeLongitudeProjection.h"
Expand Down
2 changes: 1 addition & 1 deletion src/TimeUnit.cc
Expand Up @@ -23,7 +23,7 @@

#include <boost/date_time/posix_time/posix_time.hpp>
#include "fimex/TimeUnit.h"
#include "fimex/MutexLock.h"
#include "MutexLock.h"
#include "fimex/Utils.h"
#include <limits>

Expand Down
2 changes: 1 addition & 1 deletion src/Units.cc
Expand Up @@ -27,7 +27,7 @@
#include "fimex/Logger.h"

#include "boost/shared_ptr.hpp"
#include "fimex/MutexLock.h"
#include "MutexLock.h"
#include "../config.h"
#ifdef HAVE_UDUNITS2_H
#include "udunits2.h"
Expand Down
2 changes: 1 addition & 1 deletion src/WdbCDMReader.cc
Expand Up @@ -40,7 +40,7 @@
#include "fimex/CDM.h"
#include "fimex/Data.h"
#include "fimex/Logger.h"
#include "fimex/MutexLock.h"
#include "MutexLock.h"
#include "wdb/Wdb2CdmBuilder.h"
#include "wdb/WdbIndex.h"
#include "wdb/config/GlobalWdbConfiguration.h"
Expand Down

0 comments on commit 009e084

Please sign in to comment.