VirtualBox

Ignore:
Timestamp:
Apr 16, 2008 5:50:24 PM (17 years ago)
Author:
vboxsync
Message:

Main/Settigs: Redone semi-faulty r29679: When reading from settings files, reopen them instead of reusing the existing hande to allow for concurrent multithreaded reads. Provided libxml2/libxslt reentrance (using global serialization) when parsing settings files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/xml/Settings.cpp

    r8029 r8055  
    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;
     
    347352        : fileName (NULL), handle (NIL_RTFILE), opened (false) {}
    348353
    349     Mode mode;
    350354    char *fileName;
    351355    RTFILE handle;
     
    356360    : m (new Data())
    357361{
    358     m->mode = aMode;
    359 
    360362    m->fileName = RTStrDup (aFileName);
    361363    if (m->fileName == NULL)
     
    365367    switch (aMode)
    366368    {
    367         case Read:
     369        case Mode_Read:
    368370            flags = RTFILE_O_READ;
    369371            break;
    370         case Write:
     372        case Mode_Write:
    371373            flags = RTFILE_O_WRITE | RTFILE_O_CREATE;
    372374            break;
    373         case ReadWrite:
     375        case Mode_ReadWrite:
    374376            flags = RTFILE_O_READ | RTFILE_O_WRITE;
    375377    }
     
    382384}
    383385
    384 File::File (Mode aMode, RTFILE aHandle, const char *aFileName /* = NULL */ )
     386File::File (RTFILE aHandle, const char *aFileName /* = NULL */)
    385387    : m (new Data())
    386388{
     
    388390        throw EInvalidArg (RT_SRC_POS);
    389391
    390     m->mode = aMode;
    391392    m->handle = aHandle;
    392393
     
    903904    m->trappedErr.reset();
    904905
    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).*/
     906    /* We use the global lock for the whole duration of this method to serialize
     907     * access to thread-unsafe xmlGetExternalEntityLoader() and some other
     908     * calls. It means that only one thread is able to parse an XML stream at a
     909     * time but another choice would be to patch libxml2/libxslt which is
     910     * unwanted now for several reasons. Search for "thread-safe" to find all
     911     * unsafe cases. */
     912    RTLock alock (gGlobal.xml.lock);
     913
    912914    xmlExternalEntityLoader oldEntityLoader = xmlGetExternalEntityLoader();
    913915    sThat = this;
Note: See TracChangeset for help on using the changeset viewer.

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