Skip to content

Commit

Permalink
Updated the ReadModuleDebugValue() template method to include the def…
Browse files Browse the repository at this point in the history
…ault value.

Can now be used to read strings too.
  • Loading branch information
xvitaly committed Oct 18, 2024
1 parent 85cd015 commit 2d6e047
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/lib/zswapdebug/zswapdebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ bool ZSwapDebug::IsDebugAvailable() const
}

template <typename T>
T ZSwapDebug::ReadModuleDebugValue(const std::string& Name) const
T ZSwapDebug::ReadModuleDebugValue(const std::string& Name, const T& Default) const
{
const std::string FullPath = ModuleDebugPath + Name;
T Result = 0;
T Result = Default;

if (std::filesystem::exists(FullPath))
{
Expand All @@ -92,10 +92,10 @@ T ZSwapDebug::ReadModuleDebugValue(const std::string& Name) const

long ZSwapDebug::ReadModuleDebugValueSigned(const std::string& Name) const
{
return ReadModuleDebugValue<long>(Name);
return ReadModuleDebugValue<long>(Name, 0U);
}

unsigned long ZSwapDebug::ReadModuleDebugValueUnsigned(const std::string& Name) const
{
return ReadModuleDebugValue<unsigned long>(Name);
return ReadModuleDebugValue<unsigned long>(Name, 0UL);
}
3 changes: 2 additions & 1 deletion src/lib/zswapdebug/zswapdebug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ class ZSwapDebug
* Reads the debug value of the ZSwap kernel module by the
* specified name. Template function.
* @param Name Debug value name.
* @param Default Default value.
* @returns Value of the specified type.
*/
template <typename T>
T ReadModuleDebugValue(const std::string&) const;
T ReadModuleDebugValue(const std::string&, const T&) const;
};

#endif // ZSWAPDEBUG_HPP

0 comments on commit 2d6e047

Please sign in to comment.