Skip to content

Commit

Permalink
Improve logging of SDDisk's retain()/release()
Browse files Browse the repository at this point in the history
  • Loading branch information
cholonam committed Jul 19, 2020
1 parent a50a0f2 commit 375d91f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Sinetek-rtsx/SDDisk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ bool SDDisk::init(struct sdmmc_softc *sc_sdmmc, OSDictionary* properties)

card_is_write_protected_ = true;
sdmmc_softc_ = sc_sdmmc;
#if RTSX_DEBUG_RETAIN_RELEASE
debugRetainReleaseEnabled = false;
debugRetainReleaseCount = 0;
#endif


UTL_DEBUG_FUN("END");
return true;
Expand Down Expand Up @@ -489,27 +494,33 @@ IOReturn SDDisk::message(UInt32 type, IOService *provider, void *argument)
#endif // RTSX_DEBUG_MESSAGES_RECEIVED

#if RTSX_DEBUG_RETAIN_RELEASE
int mhc_count;
void SDDisk::debugRetainRelease(bool enabled) {
debugRetainReleaseEnabled = enabled;
}

void SDDisk::taggedRetain(const void * tag) const {
if (tag) {
if (debugRetainReleaseEnabled) {
UTL_DEBUG_DEF(" Retain! (tag=%s from "
RTSX_PTR_FMT ") (%d) (%d -> %d)",
((OSMetaClass *)tag)->getClassName(),
RTSX_PTR_FMT ") (retCnt: %d -> %d) (%d -> %d)",
tag ? ((OSMetaClass *)tag)->getClassName() : "(null)",
RTSX_PTR_FMT_VAR(__builtin_return_address(0)),
getRetainCount(), mhc_count, mhc_count + 1);
mhc_count++;
getRetainCount(), getRetainCount() + 1,
debugRetainReleaseCount, debugRetainReleaseCount + 1);
debugRetainReleaseCount++;
}
super::taggedRetain(tag);
}
void SDDisk::taggedRelease(const void * tag, const int when) const {
super::taggedRelease(tag, when);
if (tag) {
mhc_count--;
// release may actually free the object, so we have to do the logging first
if (debugRetainReleaseEnabled) {
UTL_DEBUG_DEF(" Release! (tag=%s from "
RTSX_PTR_FMT ") (%d) (%d -> %d)",
((OSMetaClass *)tag)->getClassName(),
RTSX_PTR_FMT ") (retCnt: %d -> %d) (%d -> %d)",
tag ? ((OSMetaClass *)tag)->getClassName() : "(null)",
RTSX_PTR_FMT_VAR(__builtin_return_address(0)),
getRetainCount(), mhc_count + 1, mhc_count);
getRetainCount(), getRetainCount() - 1,
debugRetainReleaseCount, debugRetainReleaseCount - 1);
debugRetainReleaseCount--;
}
super::taggedRelease(tag, when);
}
#endif // RTSX_DEBUG_RETAIN_RELEASE
4 changes: 4 additions & 0 deletions Sinetek-rtsx/SDDisk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class SDDisk : public IOBlockStorageDevice
#endif

#if RTSX_DEBUG_RETAIN_RELEASE
bool debugRetainReleaseEnabled;
mutable int debugRetainReleaseCount; // to be modified by const functions
void debugRetainRelease(bool enabled);

virtual void taggedRetain(const void * tag) const override;
virtual void taggedRelease(const void * tag, const int when) const override;
#endif
Expand Down
6 changes: 6 additions & 0 deletions Sinetek-rtsx/Sinetek_rtsx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,17 @@ void Sinetek_rtsx::blk_attach()
}
sddisk_ = OSTypeAlloc(SDDisk); // equivalent to new SDDisk();
UTL_CHK_PTR(sddisk_,);
#if RTSX_DEBUG_RETAIN_RELEASE
sddisk_->debugRetainRelease(true);
#endif
if (!sddisk_->init((struct sdmmc_softc *) rtsx_softc_original_->sdmmc)) { // TODO: Fix this!
UTL_ERR("SDDisk initialization failed!");
UTL_SAFE_RELEASE_NULL(sddisk_);
return;
};
#if RTSX_DEBUG_RETAIN_RELEASE
sddisk_->debugRetainRelease(true);
#endif
sddisk_->attach(this);
UTL_DEBUG_DEF("Registering service...");
sddisk_->registerService(); // this should probably be called by the start() method of sddisk_
Expand Down

0 comments on commit 375d91f

Please # to comment.