diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2015-10-07 06:27:37 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2015-10-07 06:27:37 (GMT) |
commit | c3c1bc333e799ec747ec1919a86ae21599fa357d (patch) | |
tree | ab58121ab3a63bacd4d40ab177b340b951da9ba0 /c++/src/H5DxferProp.cpp | |
parent | 2145b1a102a6e7e2b9ea6f7bc66feca61e2c70f8 (diff) | |
download | hdf5-c3c1bc333e799ec747ec1919a86ae21599fa357d.zip hdf5-c3c1bc333e799ec747ec1919a86ae21599fa357d.tar.gz hdf5-c3c1bc333e799ec747ec1919a86ae21599fa357d.tar.bz2 |
[svn-r27983] Description:
Merged from trunk r27945, which was merged from hdf5_CppAPI_Constants,
including the revisions listed below.
Platforms tested:
Linux/32 2.6 (jam)
Linux/64 (platypus)
Darwin (osx1010test)
+++ Log message when merged from hdf5_CppAPI_Constants to trunk, r27945 +++
Purpose: Fix HDFFV-9529
Description:
Merged from hdf5_CppAPI_Constants
r27942:
------
Description:
- Added H5dont_atexit() to getPredType and all the getConstant's to prevent
the C library from terminating before the C++ library cleanup.
- More cleanup and added more comments
k
r27923:
------
- Updated more comments and moved some things around for consistency
- Removed check for "new" failure, exceptions would be thrown
r27922:
------
Description:
Added function headers and more comments for clarity.
r27917:
------
Description:
The C++ library has several types of global constants from different
classes, such as PropList, PredType, DataSpace, etc... Previously,
these global constants were declared statically and the C++ library used
a constant, called PredType::AtExit, to detect when all the global
contants are destroyed then close the C library (H5close). This method
relied on the order of the constants being created and destroyed and
that PredType constants be the last to be destroyed. In September 2015,
it was recognized that the order in which the global constants were
created and destroyed was actually undefined, thus can be different
between different compilers. This resulted in failure when compilers
destroy PredType constants before others because when PredType::AtExit
was destroyed, the C library was closed, so when the constants of other
classes such as PropList or DataSpace were being deleted, the C library
would not be available.
Solution:
The static approach is changed to dynamic. In order to avoid an impact
on existing applications, the static global constants are changed to
constant references to the dynamically allocated objects.
A detailed explanation of the new method and a description of the
changes are in a Design Notes at the end of the file H5PredType.cpp.
New functions added to support the new methods are listed below.
class H5Library:
// Returns a singleton H5Library to initialize the global
// constants, invoked in IdComponent default constructor
static H5Library* getInstance(); // public
// Registers cleanup and terminating functions with atexit(),
// called in IdComponent default constructor
static void initH5cpp(void); // public
// Calls H5close to terminate the library, registered with
// atexit(), as the last thing to be done.
static void termH5cpp(void); // public
class PredType:
// Creates the constants
static void makePredTypes(); // private
// Calls makePredTypes to create the constants and returns
// the dummy constant PREDTYPE_CONST;
static PredType* getPredTypes(); // private
class DataSpace:
// Creates the constant
static DataSpace* getConstant(); // private
class PropList:
// Creates the constant
static PropList* getConstant(); // private
class DSetCreatPropList:
// Creates the constant
static DSetCreatPropList* getConstant(); // private
class DSetMemXferPropList:
// Creates the constant
static DSetMemXferPropList* getConstant(); // private
class FileCreatPropList:
// Creates the constant
static FileCreatPropList* getConstant(); // private
class FileAccPropList:
// Creates the constant
static FileAccPropList* getConstant(); // private
This function is added to PredType, DataSpace, PropList, and the four
subclasses of PropList:
// Deletes the constant
static void deleteConstants(); // public
Diffstat (limited to 'c++/src/H5DxferProp.cpp')
-rw-r--r-- | c++/src/H5DxferProp.cpp | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/c++/src/H5DxferProp.cpp b/c++/src/H5DxferProp.cpp index 1f4a638..49bbfe6 100644 --- a/c++/src/H5DxferProp.cpp +++ b/c++/src/H5DxferProp.cpp @@ -22,24 +22,67 @@ #include "H5DxferProp.h" #include "H5private.h" // for HDmemset -#include <iostream> - #ifndef H5_NO_NAMESPACE -#ifndef H5_NO_STD - using std::cerr; - using std::endl; -#endif // H5_NO_STD +namespace H5 { #endif +#ifndef DOXYGEN_SHOULD_SKIP_THIS +// This DOXYGEN_SHOULD_SKIP_THIS block is a work-around approach to control +// the order of creation and deletion of the global constants. See Design Notes +// in "H5PredType.cpp" for information. -#ifndef H5_NO_NAMESPACE -namespace H5 { -#endif +// Initialize a pointer for the constant +DSetMemXferPropList* DSetMemXferPropList::DEFAULT_ = 0; //-------------------------------------------------------------------------- -///\brief Constant for default dataset memory and transfer property list. +// Function: DSetMemXferPropList::getConstant +// Creates a DSetMemXferPropList object representing the HDF5 +// constant H5P_DATASET_XFER, pointed to by +// DSetMemXferPropList::DEFAULT_ +// exception H5::PropListIException +// Description +// If DSetMemXferPropList::DEFAULT_ already points to an allocated +// object, throw a PropListIException. This scenario should not +// happen. +// Programmer Binh-Minh Ribler - 2015 //-------------------------------------------------------------------------- -const DSetMemXferPropList DSetMemXferPropList::DEFAULT; +DSetMemXferPropList* DSetMemXferPropList::getConstant() +{ + // Tell the C library not to clean up, H5Library::termH5cpp will call + // H5close - more dependency if use H5Library::dontAtExit() + if (!IdComponent::H5dontAtexit_called) + { + (void) H5dont_atexit(); + IdComponent::H5dontAtexit_called = true; + } + + // If the constant pointer is not allocated, allocate it. Otherwise, + // throw because it shouldn't be. + if (DEFAULT_ == 0) + DEFAULT_ = new DSetMemXferPropList(H5P_DATASET_XFER); + else + throw PropListIException("DSetMemXferPropList::getConstant", "DSetMemXferPropList::getConstant is being invoked on an allocated DEFAULT_"); + return(DEFAULT_); +} + +//-------------------------------------------------------------------------- +// Function: DSetMemXferPropList::deleteConstants +// Purpose: Deletes the constant object that DSetMemXferPropList::DEFAULT_ +// points to. +// Programmer Binh-Minh Ribler - 2015 +//-------------------------------------------------------------------------- +void DSetMemXferPropList::deleteConstants() +{ + if (DEFAULT_ != 0) + delete DEFAULT_; +} + +//-------------------------------------------------------------------------- +// Purpose Constant for default dataset memory and transfer property list. +//-------------------------------------------------------------------------- +const DSetMemXferPropList& DSetMemXferPropList::DEFAULT = *getConstant(); + +#endif // DOXYGEN_SHOULD_SKIP_THIS //-------------------------------------------------------------------------- // Function DSetMemXferPropList default constructor |