- Timestamp:
- Apr 16, 2008 10:14:39 AM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 29679
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/settings.h
r7388 r8020 81 81 * Making deep copies or detaching the existing shallow copy from its original 82 82 * 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. 83 88 * 84 89 * Due to some (not propely studied) libxml2 limitations, the Settings File … … 1171 1176 * regular files. 1172 1177 * 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. 1174 1186 */ 1175 1187 class VBOXSETTINGS_CLASS File : public Input, public Output … … 1192 1204 File (Mode aMode, const char *aFileName); 1193 1205 1206 #if 0 1207 /// @todo disabled until made thread-safe by using handle duplicates 1194 1208 /** 1195 1209 * Uses the given file handle to perform file operations. The given file … … 1204 1218 * this object destruction. 1205 1219 * 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 * 1206 1225 * @param aHandle Open file handle. 1207 1226 * @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 1211 1231 1212 1232 /** … … 1282 1302 /** 1283 1303 * 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. 1284 1318 */ 1285 1319 class VBOXSETTINGS_CLASS XmlTreeBackend : public TreeBackend -
trunk/src/VBox/Main/MachineImpl.cpp
r7992 r8020 2032 2032 2033 2033 /* load the config file */ 2034 #if 0 2035 /// @todo disabled until made thread-safe by using handle duplicates 2034 2036 File file (File::ReadWrite, mData->mHandleCfgFile, 2035 2037 Utf8Str (mData->mConfigFileFull)); 2038 #else 2039 File file (File::Read, Utf8Str (mData->mConfigFileFull)); 2040 #endif 2036 2041 XmlTreeBackend tree; 2037 2042 … … 2134 2139 2135 2140 /* load the config file */ 2141 #if 0 2142 /// @todo disabled until made thread-safe by using handle duplicates 2136 2143 File file (File::ReadWrite, mData->mHandleCfgFile, 2137 2144 Utf8Str (mData->mConfigFileFull)); 2145 #else 2146 File file (File::Read, Utf8Str (mData->mConfigFileFull)); 2147 #endif 2138 2148 XmlTreeBackend tree; 2139 2149 … … 2207 2217 2208 2218 /* load the config file */ 2219 #if 0 2220 /// @todo disabled until made thread-safe by using handle duplicates 2209 2221 File file (File::ReadWrite, mData->mHandleCfgFile, 2210 2222 Utf8Str (mData->mConfigFileFull)); 2223 #else 2224 File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull)); 2225 #endif 2211 2226 XmlTreeBackend tree; 2212 2227 … … 4005 4020 using namespace settings; 4006 4021 4022 #if 0 4023 /// @todo disabled until made thread-safe by using handle duplicates 4007 4024 File file (File::Read, mData->mHandleCfgFile, 4008 4025 Utf8Str (mData->mConfigFileFull)); 4026 #else 4027 File file (File::Read, Utf8Str (mData->mConfigFileFull)); 4028 #endif 4009 4029 XmlTreeBackend tree; 4010 4030 … … 5141 5161 using namespace settings; 5142 5162 5163 #if 0 5164 /// @todo disabled until made thread-safe by using handle duplicates 5143 5165 File file (File::ReadWrite, mData->mHandleCfgFile, 5144 5166 Utf8Str (mData->mConfigFileFull)); 5167 #else 5168 File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull)); 5169 #endif 5145 5170 XmlTreeBackend tree; 5146 5171 … … 5348 5373 5349 5374 /* load the config file */ 5375 #if 0 5376 /// @todo disabled until made thread-safe by using handle duplicates 5350 5377 File file (File::ReadWrite, mData->mHandleCfgFile, 5351 5378 Utf8Str (mData->mConfigFileFull)); 5379 #else 5380 File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull)); 5381 #endif 5352 5382 XmlTreeBackend tree; 5353 5383 … … 5925 5955 5926 5956 /* load the config file */ 5957 #if 0 5958 /// @todo disabled until made thread-safe by using handle duplicates 5927 5959 File file (File::ReadWrite, mData->mHandleCfgFile, 5928 5960 Utf8Str (mData->mConfigFileFull)); 5961 #else 5962 File file (File::ReadWrite, Utf8Str (mData->mConfigFileFull)); 5963 #endif 5929 5964 XmlTreeBackend tree; 5930 5965 -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r7964 r8020 206 206 using namespace settings; 207 207 208 #if 0 209 /// @todo disabled until made thread-safe by using handle duplicates 208 210 File file (File::ReadWrite, mData.mCfgFile.mHandle, vboxConfigFile); 211 #else 212 File file (File::Read, vboxConfigFile); 213 #endif 209 214 XmlTreeBackend tree; 210 215 … … 1709 1714 1710 1715 /* load the config file */ 1716 #if 0 1717 /// @todo disabled until made thread-safe by using handle duplicates 1711 1718 File file (File::ReadWrite, mData.mCfgFile.mHandle, 1712 1719 Utf8Str (mData.mCfgFile.mName)); 1720 #else 1721 File file (File::Read, Utf8Str (mData.mCfgFile.mName)); 1722 #endif 1713 1723 XmlTreeBackend tree; 1714 1724 … … 1807 1817 1808 1818 /* load the config file */ 1819 #if 0 1820 /// @todo disabled until made thread-safe by using handle duplicates 1809 1821 File file (File::ReadWrite, mData.mCfgFile.mHandle, 1810 1822 Utf8Str (mData.mCfgFile.mName)); 1823 #else 1824 File file (File::Read, Utf8Str (mData.mCfgFile.mName)); 1825 #endif 1811 1826 XmlTreeBackend tree; 1812 1827 … … 1867 1882 1868 1883 /* load the config file */ 1884 #if 0 1885 /// @todo disabled until made thread-safe by using handle duplicates 1869 1886 File file (File::ReadWrite, mData.mCfgFile.mHandle, 1870 1887 Utf8Str (mData.mCfgFile.mName)); 1888 #else 1889 File file (File::ReadWrite, Utf8Str (mData.mCfgFile.mName)); 1890 #endif 1871 1891 XmlTreeBackend tree; 1872 1892 … … 3721 3741 using namespace settings; 3722 3742 3743 #if 0 3744 /// @todo disabled until made thread-safe by using handle duplicates 3723 3745 File file (File::ReadWrite, mData.mCfgFile.mHandle, 3724 3746 Utf8Str (mData.mCfgFile.mName)); 3747 #else 3748 File file (File::ReadWrite, Utf8Str (mData.mCfgFile.mName)); 3749 #endif 3725 3750 XmlTreeBackend tree; 3726 3751 -
trunk/src/VBox/Main/xml/Settings.cpp
r7387 r8020 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; … … 382 387 } 383 388 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 391 File::File (Mode aMode, RTFILE aHandle, const char *aFileName) 385 392 : m (new Data()) 386 393 { … … 400 407 setPos (0); 401 408 } 409 #endif 402 410 403 411 File::~File() … … 903 911 m->trappedErr.reset(); 904 912 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 912 921 xmlExternalEntityLoader oldEntityLoader = xmlGetExternalEntityLoader(); 913 922 sThat = this;
Note:
See TracChangeset
for help on using the changeset viewer.