Changeset 95714 in vbox
- Timestamp:
- Jul 18, 2022 4:13:16 PM (3 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/RecordingScreenSettingsImpl.h
r95639 r95714 59 59 60 60 settings::RecordingScreenSettings &i_getData(void); 61 62 int32_t i_reference(void); 63 int32_t i_release(void); 64 int32_t i_getReferences(void); 61 65 62 66 private: -
trunk/src/VBox/Main/src-server/RecordingScreenSettingsImpl.cpp
r95639 r95714 42 42 Data() 43 43 : pParent(NULL) 44 , cRefs(0) 44 45 { } 45 46 … … 47 48 const ComObjPtr<RecordingScreenSettings> pPeer; 48 49 uint32_t uScreenId; 50 /** Internal reference count to track sharing of this screen settings object among 51 * other recording settings objects. */ 52 int32_t cRefs; 49 53 50 54 // use the XML settings structure in the members for simplicity … … 146 150 m->bd.share(aThat->m->bd); 147 151 148 HRESULT rc = S_OK;152 HRESULT hrc = S_OK; 149 153 150 154 int vrc = i_initInternal(); … … 156 160 { 157 161 autoInitSpan.setFailed(); 158 rc = E_UNEXPECTED;162 hrc = E_UNEXPECTED; 159 163 } 160 164 161 165 LogFlowThisFuncLeave(); 162 return rc;166 return hrc; 163 167 } 164 168 … … 214 218 void RecordingScreenSettings::uninit() 215 219 { 216 Log FlowThisFuncEnter();220 LogThisFunc(("%p\n", this)); 217 221 218 222 /* Enclose the state transition Ready->InUninit->NotReady */ … … 221 225 return; 222 226 227 /* Make sure nobody holds an internal reference to it anymore. */ 228 AssertReturnVoid(m->cRefs == 0); 229 223 230 m->bd.free(); 224 231 … … 930 937 { 931 938 AssertPtrReturn(m, VERR_INVALID_POINTER); 939 940 i_reference(); 932 941 933 942 int vrc = i_parseOptionsString(m->bd->strOptions, *m->bd.data()); … … 983 992 HRESULT RecordingScreenSettings::i_saveSettings(settings::RecordingScreenSettings &data) 984 993 { 994 LogThisFunc(("%p: Screen %RU32\n", this, m ? m->uScreenId : UINT32_MAX)); 995 985 996 /* sanity */ 986 997 AutoCaller autoCaller(this); … … 1071 1082 AssertPtr(m); 1072 1083 return *m->bd.data(); 1084 } 1085 1086 /** 1087 * Increments the reference count. 1088 * 1089 * @returns New reference count. 1090 * 1091 * @note Internal reference count, to track object sharing across different recording settings objects 1092 * which share the same screen recording data. 1093 */ 1094 int32_t RecordingScreenSettings::i_reference(void) 1095 { 1096 int cNewRefs = ASMAtomicIncS32(&m->cRefs); RT_NOREF(cNewRefs); 1097 LogThisFunc(("%p: cRefs -> %RI32\n", this, cNewRefs)); 1098 return cNewRefs; 1099 } 1100 1101 /** 1102 * Decrements the reference count. 1103 * 1104 * @returns New reference count. 1105 * 1106 * @note Internal reference count, to track object sharing across different recording settings objects 1107 * which share the same screen recording data. 1108 */ 1109 int32_t RecordingScreenSettings::i_release(void) 1110 { 1111 int32_t cNewRefs = ASMAtomicDecS32(&m->cRefs); RT_NOREF(cNewRefs); 1112 LogThisFunc(("%p: cRefs -> %RI32\n", this, cNewRefs)); 1113 AssertReturn(cNewRefs >= 0, 0); 1114 return cNewRefs; 1115 } 1116 1117 /** 1118 * Returns the current reference count. 1119 * 1120 * @returns Current reference count. 1121 * 1122 * @note Internal reference count, to track object sharing across different recording settings objects 1123 * which share the same screen recording data. 1124 */ 1125 int32_t RecordingScreenSettings::i_getReferences(void) 1126 { 1127 return ASMAtomicReadS32(&m->cRefs); 1073 1128 } 1074 1129 -
trunk/src/VBox/Main/src-server/RecordingSettingsImpl.cpp
r95663 r95714 127 127 128 128 m->bd.share(aThat->m->bd); 129 130 /* Make sure to add a reference when sharing the screen objects with aThat. */ 131 for (RecordingScreenSettingsObjMap::const_iterator itScreenThat = aThat->m->mapScreenObj.begin(); 132 itScreenThat != aThat->m->mapScreenObj.end(); 133 ++itScreenThat) 134 itScreenThat->second->i_reference(); 135 129 136 m->mapScreenObj = aThat->m->mapScreenObj; 130 137 … … 202 209 return; 203 210 204 /* Note: Do *not* call i_reset() here, as the shared recording configuration 205 * otherwise gets destructed when this object goes out of scope or is destroyed. */ 211 /* Make sure to destroy screen objects attached to this object. 212 * Note: This also decrements the refcount of a screens object, in case it's shared among other recording settings. */ 213 i_destroyAllScreenObj(m->mapScreenObj); 206 214 207 215 m->bd.free(); … … 369 377 AssertReturn(screenSettingsMap.find(idScreen) == screenSettingsMap.end(), VERR_ALREADY_EXISTS); 370 378 371 LogFlowThisFunc(("Screen %RU32\n", idScreen));372 373 379 int vrc = VINF_SUCCESS; 374 380 … … 391 397 } 392 398 399 LogThisFunc(("%p: Screen %RU32 -> %Rrc\n", recordingScreenSettings.m_p, idScreen, vrc)); 393 400 return vrc; 394 401 } … … 397 404 * Removes a screen settings object from a particular map. 398 405 * 399 * @returns IPRT status code. VERR_NOT_FOUND if specified screen was not found. 406 * If the internal reference count hits 0, the screen settings object will be destroyed. 407 * This means that this screen settings object is not being used anymore by other recording settings (as shared data). 408 * 409 * @returns IPRT status code. 410 * @retval VERR_NOT_FOUND if specified screen was not found. 400 411 * @param screenSettingsMap Map to remove screen settings from. 401 412 * @param idScreen ID of screen to remove. … … 403 414 int RecordingSettings::i_destroyScreenObj(RecordingScreenSettingsObjMap &screenSettingsMap, uint32_t idScreen) 404 415 { 405 LogFlowThisFunc(("Screen %RU32\n", idScreen));406 407 AssertReturn(idScreen > 0, VERR_INVALID_PARAMETER); /* Removing screen 0 isn't a good idea. */408 416 AssertReturn(screenSettingsMap.find(idScreen) != screenSettingsMap.end(), VERR_NOT_FOUND); 409 417 … … 416 424 screenSettingsMap.erase(itScreen); 417 425 418 pScreenSettings.setNull(); 426 LogThisFunc(("%p: Screen %RU32, cRefs=%RI32\n", pScreenSettings.m_p, idScreen, pScreenSettings->i_getReferences())); 427 428 pScreenSettings->i_release(); 429 430 /* Only destroy the object if nobody else keeps a reference to it anymore. */ 431 if (pScreenSettings->i_getReferences() == 0) 432 { 433 LogThisFunc(("%p: Screen %RU32 -> Null\n", pScreenSettings.m_p, idScreen)); 434 pScreenSettings.setNull(); 435 } 419 436 420 437 return VINF_SUCCESS; … … 431 448 LogFlowThisFuncEnter(); 432 449 433 RecordingScreenSettingsObjMap::iterator itScreenObj = screenSettingsMap.begin(); 434 while (itScreenObj != screenSettingsMap.end()) 435 { 436 /* Make sure to consume the pointer before the one of the 437 * iterator gets released. */ 438 ComObjPtr<RecordingScreenSettings> pScreenSettings = itScreenObj->second; 439 440 screenSettingsMap.erase(itScreenObj); 441 442 pScreenSettings->uninit(); 443 pScreenSettings.setNull(); 444 445 itScreenObj = screenSettingsMap.begin(); 450 int vrc = VINF_SUCCESS; 451 452 RecordingScreenSettingsObjMap::iterator itScreen = screenSettingsMap.begin(); 453 while (itScreen != screenSettingsMap.end()) 454 { 455 vrc = i_destroyScreenObj(screenSettingsMap, itScreen->first); 456 if (RT_FAILURE(vrc)) 457 break; 458 459 itScreen = screenSettingsMap.begin(); 446 460 } 447 461 448 462 Assert(screenSettingsMap.size() == 0); 449 return VINF_SUCCESS;463 return vrc; 450 464 } 451 465 … … 748 762 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 749 763 764 LogThisFunc(("%p: cDisplays=%RU32 vs. %zu\n", this, cDisplays, m->mapScreenObj.size())); 765 750 766 /* If counts match, take a shortcut. */ 751 767 if (cDisplays == m->mapScreenObj.size())
Note:
See TracChangeset
for help on using the changeset viewer.