Changeset 8055 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 16, 2008 5:50:24 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 29733
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/MachineImpl.cpp
r8029 r8055 2013 2013 CheckComRCReturnRC (autoCaller.rc()); 2014 2014 2015 /* serialize file access (prevent writes) */ 2015 2016 AutoReaderLock alock (this); 2016 2017 … … 2031 2032 using namespace settings; 2032 2033 2033 /* load the config file */2034 File file (File::ReadWrite, mData->mHandleCfgFile,2035 2034 /* load the settings file (we don't reuse the existing handle but 2035 * request a new one to allow for concurrent multithreaded reads) */ 2036 File file (File::Mode_Read, Utf8Str (mData->mConfigFileFull)); 2036 2037 XmlTreeBackend tree; 2037 2038 … … 2117 2118 CheckComRCReturnRC (autoCaller.rc()); 2118 2119 2120 /* serialize file access (prevent writes) */ 2119 2121 AutoReaderLock alock (this); 2120 2122 … … 2133 2135 using namespace settings; 2134 2136 2135 /* load the config file */2136 File file (File::ReadWrite, mData->mHandleCfgFile,2137 2137 /* load the settings file (we don't reuse the existing handle but 2138 * request a new one to allow for concurrent multithreaded reads) */ 2139 File file (File::Mode_Read, Utf8Str (mData->mConfigFileFull)); 2138 2140 XmlTreeBackend tree; 2139 2141 … … 2182 2184 2183 2185 /* VirtualBox::onExtraDataCanChange() and saveSettings() need mParent 2184 * lock (saveSettings() needs a write one) */ 2186 * lock (saveSettings() needs a write one). This object's write lock is 2187 * also necessary to serialize file access (prevent concurrent reads and 2188 * writes). */ 2185 2189 AutoMultiWriteLock2 alock (mParent, this); 2186 2190 … … 2206 2210 using namespace settings; 2207 2211 2208 /* load the config file */ 2209 File file (File::ReadWrite, mData->mHandleCfgFile, 2210 Utf8Str (mData->mConfigFileFull)); 2212 /* load the settings file */ 2213 File file (mData->mHandleCfgFile, Utf8Str (mData->mConfigFileFull)); 2211 2214 XmlTreeBackend tree; 2212 2215 … … 4005 4008 using namespace settings; 4006 4009 4007 File file (File::Read, mData->mHandleCfgFile,4008 4010 /* no concurrent file access is possible in init() so open by handle */ 4011 File file (mData->mHandleCfgFile, Utf8Str (mData->mConfigFileFull)); 4009 4012 XmlTreeBackend tree; 4010 4013 … … 5141 5144 using namespace settings; 5142 5145 5143 File file (File::ReadWrite, mData->mHandleCfgFile,5144 5146 /* this object is locked for writing to prevent concurrent reads and writes */ 5147 File file (mData->mHandleCfgFile, Utf8Str (mData->mConfigFileFull)); 5145 5148 XmlTreeBackend tree; 5146 5149 … … 5337 5340 AssertReturn (mType == IsMachine || mType == IsSessionMachine, E_FAIL); 5338 5341 5342 /* This object's write lock is also necessary to serialize file access 5343 * (prevent concurrent reads and writes) */ 5339 5344 AutoLock alock (this); 5340 5345 … … 5347 5352 using namespace settings; 5348 5353 5349 /* load the config file */ 5350 File file (File::ReadWrite, mData->mHandleCfgFile, 5351 Utf8Str (mData->mConfigFileFull)); 5354 /* load the settings file */ 5355 File file (mData->mHandleCfgFile, Utf8Str (mData->mConfigFileFull)); 5352 5356 XmlTreeBackend tree; 5353 5357 … … 5914 5918 AssertComRCReturn (autoCaller.rc(), autoCaller.rc()); 5915 5919 5920 /* This object's write lock is also necessary to serialize file access 5921 * (prevent concurrent reads and writes) */ 5916 5922 AutoLock alock (this); 5917 5923 … … 5924 5930 using namespace settings; 5925 5931 5926 /* load the config file */ 5927 File file (File::ReadWrite, mData->mHandleCfgFile, 5928 Utf8Str (mData->mConfigFileFull)); 5932 /* load the settings file */ 5933 File file (mData->mHandleCfgFile, Utf8Str (mData->mConfigFileFull)); 5929 5934 XmlTreeBackend tree; 5930 5935 -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r8029 r8055 206 206 using namespace settings; 207 207 208 File file (File::ReadWrite, mData.mCfgFile.mHandle, vboxConfigFile); 208 /* no concurrent file access is possible in init() so open by handle */ 209 File file (mData.mCfgFile.mHandle, vboxConfigFile); 209 210 XmlTreeBackend tree; 210 211 … … 1701 1702 HRESULT rc = S_OK; 1702 1703 1703 /* serialize config file access*/1704 /* serialize file access (prevent writes) */ 1704 1705 AutoReaderLock alock (this); 1705 1706 … … 1708 1709 using namespace settings; 1709 1710 1710 /* load the config file */1711 File file (File::ReadWrite, mData.mCfgFile.mHandle,1712 1711 /* load the settings file (we don't reuse the existing handle but 1712 * request a new one to allow for concurrent multithreaded reads) */ 1713 File file (File::Mode_Read, Utf8Str (mData.mCfgFile.mName)); 1713 1714 XmlTreeBackend tree; 1714 1715 … … 1799 1800 HRESULT rc = S_OK; 1800 1801 1801 /* serialize file access */1802 /* serialize file access (prevent writes) */ 1802 1803 AutoReaderLock alock (this); 1803 1804 … … 1806 1807 using namespace settings; 1807 1808 1808 /* load the config file */1809 File file (File::ReadWrite, mData.mCfgFile.mHandle,1810 1809 /* load the settings file (we don't reuse the existing handle but 1810 * request a new one to allow for concurrent multithreaded reads) */ 1811 File file (File::Mode_Read, Utf8Str (mData.mCfgFile.mName)); 1811 1812 XmlTreeBackend tree; 1812 1813 … … 1859 1860 HRESULT rc = S_OK; 1860 1861 1861 /* serialize file access */1862 /* serialize file access (prevent concurrent reads and writes) */ 1862 1863 AutoLock alock (this); 1863 1864 … … 1866 1867 using namespace settings; 1867 1868 1868 /* load the config file */ 1869 File file (File::ReadWrite, mData.mCfgFile.mHandle, 1870 Utf8Str (mData.mCfgFile.mName)); 1869 /* load the settings file */ 1870 File file (mData.mCfgFile.mHandle, Utf8Str (mData.mCfgFile.mName)); 1871 1871 XmlTreeBackend tree; 1872 1872 … … 3704 3704 * Helper function to write out the configuration tree. 3705 3705 * 3706 * @note Locks objects for reading!3706 * @note Locks this object for writing and child objects for reading/writing! 3707 3707 */ 3708 3708 HRESULT VirtualBox::saveSettings() … … 3715 3715 HRESULT rc = S_OK; 3716 3716 3717 AutoReaderLock alock (this); 3717 /* serialize file access (prevent concurrent reads and writes) */ 3718 AutoLock alock (this); 3718 3719 3719 3720 try … … 3721 3722 using namespace settings; 3722 3723 3723 File file (File::ReadWrite, mData.mCfgFile.mHandle,3724 3724 /* load the settings file */ 3725 File file (mData.mCfgFile.mHandle, Utf8Str (mData.mCfgFile.mName)); 3725 3726 XmlTreeBackend tree; 3726 3727 -
trunk/src/VBox/Main/xml/Settings.cpp
r8029 r8055 21 21 #include <iprt/err.h> 22 22 #include <iprt/file.h> 23 #include <iprt/lock.h> 23 24 24 25 #include <libxml/tree.h> … … 74 75 { 75 76 xmlExternalEntityLoader defaultEntityLoader; 77 78 /** Used to provide some thread safety missing in libxml2 (see e.g. 79 * XmlTreeBackend::read()) */ 80 RTLockMtx lock; 76 81 } 77 82 xml; … … 347 352 : fileName (NULL), handle (NIL_RTFILE), opened (false) {} 348 353 349 Mode mode;350 354 char *fileName; 351 355 RTFILE handle; … … 356 360 : m (new Data()) 357 361 { 358 m->mode = aMode;359 360 362 m->fileName = RTStrDup (aFileName); 361 363 if (m->fileName == NULL) … … 365 367 switch (aMode) 366 368 { 367 case Read:369 case Mode_Read: 368 370 flags = RTFILE_O_READ; 369 371 break; 370 case Write:372 case Mode_Write: 371 373 flags = RTFILE_O_WRITE | RTFILE_O_CREATE; 372 374 break; 373 case ReadWrite:375 case Mode_ReadWrite: 374 376 flags = RTFILE_O_READ | RTFILE_O_WRITE; 375 377 } … … 382 384 } 383 385 384 File::File ( Mode aMode, RTFILE aHandle, const char *aFileName /* = NULL */)386 File::File (RTFILE aHandle, const char *aFileName /* = NULL */) 385 387 : m (new Data()) 386 388 { … … 388 390 throw EInvalidArg (RT_SRC_POS); 389 391 390 m->mode = aMode;391 392 m->handle = aHandle; 392 393 … … 903 904 m->trappedErr.reset(); 904 905 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 912 914 xmlExternalEntityLoader oldEntityLoader = xmlGetExternalEntityLoader(); 913 915 sThat = this;
Note:
See TracChangeset
for help on using the changeset viewer.