Skip to content

Commit

Permalink
Merge pull request #1701 from CastagnaIT/replace_atomic
Browse files Browse the repository at this point in the history
Replaced std::atomic<struct> with mutex
  • Loading branch information
CastagnaIT authored Oct 16, 2024
2 parents 0b8bdbb + c50549a commit 4ff9952
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ else()
add_definitions(-D__STDC_FORMAT_MACROS)
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
list(APPEND DEPLIBS "atomic")
endif()

# Sources to build
# (use add_dir_sources function to add source/header files from the CMakeLists files of subdirectories)
add_subdirectory(src)
Expand Down
15 changes: 12 additions & 3 deletions src/CompResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,21 @@ class ATTR_DLL_LOCAL CCompResources
* \brief Get the current screen info.
* \return The screen info.
*/
ScreenInfo GetScreenInfo() const { return m_screenInfo.load(); }
const ScreenInfo& GetScreenInfo()
{
std::lock_guard<std::mutex> lock(m_screenInfoMutex);
return m_screenInfo;
}

/*!
* \brief Set the screen info.
* \param screenInfo The scren info
*/
void SetScreenInfo(const ScreenInfo& screenInfo) { m_screenInfo = screenInfo; }
void SetScreenInfo(const ScreenInfo& screenInfo)
{
std::lock_guard<std::mutex> lock(m_screenInfoMutex);
m_screenInfo = screenInfo;
}

/*!
* \brief Cookies that can be shared along with HTTP requests.
Expand All @@ -87,7 +95,8 @@ class ATTR_DLL_LOCAL CCompResources
const adaptive::AdaptiveTree& GetTree() const { return *m_tree; }

private:
std::atomic<ScreenInfo> m_screenInfo;
ScreenInfo m_screenInfo;
std::mutex m_screenInfoMutex;
std::unordered_set<UTILS::CURL::Cookie> m_cookies;
std::mutex m_cookiesMutex;
adaptive::AdaptiveTree* m_tree{nullptr};
Expand Down
2 changes: 1 addition & 1 deletion src/common/Chooser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ CHOOSER::IRepresentationChooser::IRepresentationChooser()

void CHOOSER::IRepresentationChooser::OnUpdateScreenRes()
{
const auto sInfo = CSrvBroker::GetResources().GetScreenInfo();
const auto& sInfo = CSrvBroker::GetResources().GetScreenInfo();

LOG::Log(LOGINFO,
"[Repr. chooser] Resolution set: %dx%d, max allowed: %dx%d, Adjust refresh rate: %i",
Expand Down
6 changes: 1 addition & 5 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ add_executable(${BINARY}
../utils/XMLUtils.cpp
)

if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
SET(ADD_LINK_LIBS "atomic")
endif()

target_link_libraries(${BINARY} PRIVATE ${BENTO4_LIBRARIES} ${PUGIXML_LIBRARIES} ${GTEST_LIBRARIES} Threads::Threads ${CMAKE_DL_LIBS} ${ADD_LINK_LIBS})
target_link_libraries(${BINARY} PRIVATE ${BENTO4_LIBRARIES} ${PUGIXML_LIBRARIES} ${GTEST_LIBRARIES} Threads::Threads ${CMAKE_DL_LIBS})

set(TEST_DATA_DIR "${CMAKE_SOURCE_DIR}/src/test/manifests")
add_test(NAME manifest_tests COMMAND ${BINARY} "${TEST_DATA_DIR}")

0 comments on commit 4ff9952

Please sign in to comment.