VirtualBox

Changeset 8020 in vbox for trunk


Ignore:
Timestamp:
Apr 16, 2008 10:14:39 AM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
29679
Message:

Main/Settigs: Disabled File (..., RTFILE aHandle, ...) constructor since it is not thread-safe when the handle is shared across different File instances (needs a handle duplicate operation in the IPRT File API).

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/settings.h

    r7388 r8020  
    8181 * Making deep copies or detaching the existing shallow copy from its original
    8282 * is not yet supported.
     83 *
     84 * Note that the Settings File API is not thread-safe. It means that if you
     85 * want to use the same instance of a class from the settings namespace on more
     86 * than one thread at a time, you will have to provide necessary access
     87 * serialization yourself.
    8388 *
    8489 * Due to some (not propely studied) libxml2 limitations, the Settings File
     
    11711176 * regular files.
    11721177 *
    1173  * The File class uses IPRT File API for file operations.
     1178 * The File class uses IPRT File API for file operations. Note that IPRT File
     1179 * API is not thread-safe. This means that if you pass the same RTFILE handle to
     1180 * different File instances that may be simultaneously used on different
     1181 * threads, you should care about serialization; otherwise you will get garbage
     1182 * when reading from such File instances.
     1183 *
     1184 * @todo We should duplicate file handles (once this API is in IPRT) passed to
     1185 *       constructors to provide thread-safety.
    11741186 */
    11751187class VBOXSETTINGS_CLASS File : public Input, public Output
     
    11921204    File (Mode aMode, const char *aFileName);
    11931205
     1206#if 0
     1207    /// @todo disabled until made thread-safe by using handle duplicates
    11941208    /**
    11951209     * Uses the given file handle to perform file operations. The given file
     
    12041218     * this object destruction.
    12051219     *
     1220     * @note It you pass the same RTFILE handle to more than one File instance,
     1221     *       please make sure you have provided serialization in case if these
     1222     *       instasnces are to be simultaneously used by different threads.
     1223     *       Otherwise you may get garbage when reading or writing.
     1224     *
    12061225     * @param aHandle   Open file handle.
    12071226     * @param aMode     File mode of the open file handle.
    1208      * @param aFileName File name (for reference).
    1209      */
    1210     File (Mode aMode, RTFILE aHandle, const char *aFileName = NULL);
     1227     * @param aFileName File name (for reference, may be NULL).
     1228     */
     1229    File (Mode aMode, RTFILE aHandle, const char *aFileName);
     1230#endif
    12111231
    12121232    /**
     
    12821302/**
    12831303 * The XmlTreeBackend class uses XML markup to store settings trees.
     1304 *
     1305 * @note libxml2 and libxslt libraries used by the XmlTreeBackend are not
     1306 * fully reentrant. To "fix" this, the XmlTreeBackend backend serializes access
     1307 * to such non-reentrant parts using a global mutex so that only one thread can
     1308 * use non-reentrant code at a time. Currently, this relates to the #rawRead()
     1309 * method (and to #read() as a consequence). This menas that only one thread can
     1310 * parse an XML stream at a time; other threads trying to parse same or
     1311 * different streams using different XmlTreeBackend and Input instances
     1312 * will have to wait.
     1313 *
     1314 * Keep in mind that the above reentrancy fix does not imply thread-safety: it
     1315 * is still the caller's responsibility to provide serialization if the same
     1316 * XmlTreeBackend instnace (as well as instances of other classes from the
     1317 * settings namespace) needs to be used by more than one thread.
    12841318 */
    12851319class VBOXSETTINGS_CLASS XmlTreeBackend : public TreeBackend
  • trunk/src/VBox/Main/MachineImpl.cpp

    r7992 r8020  
    20322032
    20332033        /* load the config file */
     2034#if 0
     2035        /// @todo disabled until made thread-safe by using handle duplicates
    20342036        File file (File::ReadWrite, mData->mHandleCfgFile,
    20352037                   Utf8Str (mData->mConfigFileFull));
     2038#else
     2039        File file (File::Read, Utf8Str (mData->mConfigFileFull));
     2040#endif
    20362041        XmlTreeBackend tree;
    20372042
     
    21342139
    21352140        /* load the config file */
     2141#if 0
     2142        /// @todo disabled until made thread-safe by using handle duplicates
    21362143        File file (File::ReadWrite, mData->mHandleCfgFile,
    21372144                   Utf8Str (mData->mConfigFileFull));
     2145#else
     2146        File file (File::Read, Utf8Str (mData->mConfigFileFull));
     2147#endif
    21382148        XmlTreeBackend tree;
    21392149
     
    22072217
    22082218        /* load the config file */
     2219#if 0
     2220        /// @todo disabled until made thread-safe by using handle duplicates
    22092221        File file (File::ReadWrite, mData->mHandleCfgFile,
    22102222                   Utf8Str (mData->mConfigFileFull));
     2223#else
     2224        File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull));
     2225#endif
    22112226        XmlTreeBackend tree;
    22122227
     
    40054020        using namespace settings;
    40064021
     4022#if 0
     4023        /// @todo disabled until made thread-safe by using handle duplicates
    40074024        File file (File::Read, mData->mHandleCfgFile,
    40084025                   Utf8Str (mData->mConfigFileFull));
     4026#else
     4027        File file (File::Read, Utf8Str (mData->mConfigFileFull));
     4028#endif
    40094029        XmlTreeBackend tree;
    40104030
     
    51415161        using namespace settings;
    51425162
     5163#if 0
     5164        /// @todo disabled until made thread-safe by using handle duplicates
    51435165        File file (File::ReadWrite, mData->mHandleCfgFile,
    51445166                   Utf8Str (mData->mConfigFileFull));
     5167#else
     5168        File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull));
     5169#endif
    51455170        XmlTreeBackend tree;
    51465171
     
    53485373
    53495374        /* load the config file */
     5375#if 0
     5376        /// @todo disabled until made thread-safe by using handle duplicates
    53505377        File file (File::ReadWrite, mData->mHandleCfgFile,
    53515378                   Utf8Str (mData->mConfigFileFull));
     5379#else
     5380        File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull));
     5381#endif
    53525382        XmlTreeBackend tree;
    53535383
     
    59255955
    59265956        /* load the config file */
     5957#if 0
     5958        /// @todo disabled until made thread-safe by using handle duplicates
    59275959        File file (File::ReadWrite, mData->mHandleCfgFile,
    59285960                   Utf8Str (mData->mConfigFileFull));
     5961#else
     5962        File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull));
     5963#endif
    59295964        XmlTreeBackend tree;
    59305965
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r7964 r8020  
    206206            using namespace settings;
    207207
     208#if 0
     209            /// @todo disabled until made thread-safe by using handle duplicates
    208210            File file (File::ReadWrite, mData.mCfgFile.mHandle, vboxConfigFile);
     211#else
     212            File file (File::Read, vboxConfigFile);
     213#endif
    209214            XmlTreeBackend tree;
    210215
     
    17091714
    17101715        /* load the config file */
     1716#if 0
     1717        /// @todo disabled until made thread-safe by using handle duplicates
    17111718        File file (File::ReadWrite, mData.mCfgFile.mHandle,
    17121719                   Utf8Str (mData.mCfgFile.mName));
     1720#else
     1721        File file (File::Read, Utf8Str (mData.mCfgFile.mName));
     1722#endif
    17131723        XmlTreeBackend tree;
    17141724
     
    18071817
    18081818        /* load the config file */
     1819#if 0
     1820        /// @todo disabled until made thread-safe by using handle duplicates
    18091821        File file (File::ReadWrite, mData.mCfgFile.mHandle,
    18101822                   Utf8Str (mData.mCfgFile.mName));
     1823#else
     1824        File file (File::Read, Utf8Str (mData.mCfgFile.mName));
     1825#endif
    18111826        XmlTreeBackend tree;
    18121827
     
    18671882
    18681883        /* load the config file */
     1884#if 0
     1885        /// @todo disabled until made thread-safe by using handle duplicates
    18691886        File file (File::ReadWrite, mData.mCfgFile.mHandle,
    18701887                   Utf8Str (mData.mCfgFile.mName));
     1888#else
     1889        File file (File::ReadWrite, Utf8Str (mData.mCfgFile.mName));
     1890#endif
    18711891        XmlTreeBackend tree;
    18721892
     
    37213741        using namespace settings;
    37223742
     3743#if 0
     3744        /// @todo disabled until made thread-safe by using handle duplicates
    37233745        File file (File::ReadWrite, mData.mCfgFile.mHandle,
    37243746                   Utf8Str (mData.mCfgFile.mName));
     3747#else
     3748        File file (File::ReadWrite, Utf8Str (mData.mCfgFile.mName));
     3749#endif
    37253750        XmlTreeBackend tree;
    37263751
  • trunk/src/VBox/Main/xml/Settings.cpp

    r7387 r8020  
    2121#include <iprt/err.h>
    2222#include <iprt/file.h>
     23#include <iprt/lock.h>
    2324
    2425#include <libxml/tree.h>
     
    7475    {
    7576        xmlExternalEntityLoader defaultEntityLoader;
     77
     78        /** Used to provide some thread safety missing in libxml2 (see e.g.
     79         *  XmlTreeBackend::read()) */
     80        RTLockMtx lock;
    7681    }
    7782    xml;
     
    382387}
    383388
    384 File::File (Mode aMode, RTFILE aHandle, const char *aFileName /* = NULL */ )
     389#if 0
     390/// @todo disabled until made thread-safe by using handle duplicates
     391File::File (Mode aMode, RTFILE aHandle, const char *aFileName)
    385392    : m (new Data())
    386393{
     
    400407    setPos (0);
    401408}
     409#endif
    402410
    403411File::~File()
     
    903911    m->trappedErr.reset();
    904912
    905     /* Set up the external entity resolver. Note that we do it in a
    906      * thread-unsafe fashion because this stuff is not thread-safe in libxml2.
    907      * Making it thread-safe would require a) guarding this method with a
    908      * mutex and b) requiring our API caller not to use libxml2 on some other
    909      * thread (which is not practically possible). So, our API is not
    910      * thread-safe for now (note that there are more thread-unsafe assumptions
    911      * below like xsltGenericError which is also a libxslt limitation).*/
     913    /* We use the global lock for the whole duration of this method to serialize
     914     * access to thread-unsafe xmlGetExternalEntityLoader() and some other
     915     * calls. It means that only one thread is able to parse an XML stream at a
     916     * time but another choice would be to patch libxml2/libxslt which is
     917     * unwanted now for several reasons. Search for "thread-safe" to find all
     918     * unsafe cases. */
     919    RTLock alock (gGlobal.xml.lock);
     920
    912921    xmlExternalEntityLoader oldEntityLoader = xmlGetExternalEntityLoader();
    913922    sThat = this;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette