Skip to content

Commit 4ff9952

Browse files
authored
Merge pull request #1701 from CastagnaIT/replace_atomic
Replaced std::atomic<struct> with mutex
2 parents 0b8bdbb + c50549a commit 4ff9952

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ else()
3434
add_definitions(-D__STDC_FORMAT_MACROS)
3535
endif()
3636

37-
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
38-
list(APPEND DEPLIBS "atomic")
39-
endif()
40-
4137
# Sources to build
4238
# (use add_dir_sources function to add source/header files from the CMakeLists files of subdirectories)
4339
add_subdirectory(src)

src/CompResources.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,21 @@ class ATTR_DLL_LOCAL CCompResources
5959
* \brief Get the current screen info.
6060
* \return The screen info.
6161
*/
62-
ScreenInfo GetScreenInfo() const { return m_screenInfo.load(); }
62+
const ScreenInfo& GetScreenInfo()
63+
{
64+
std::lock_guard<std::mutex> lock(m_screenInfoMutex);
65+
return m_screenInfo;
66+
}
6367

6468
/*!
6569
* \brief Set the screen info.
6670
* \param screenInfo The scren info
6771
*/
68-
void SetScreenInfo(const ScreenInfo& screenInfo) { m_screenInfo = screenInfo; }
72+
void SetScreenInfo(const ScreenInfo& screenInfo)
73+
{
74+
std::lock_guard<std::mutex> lock(m_screenInfoMutex);
75+
m_screenInfo = screenInfo;
76+
}
6977

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

8997
private:
90-
std::atomic<ScreenInfo> m_screenInfo;
98+
ScreenInfo m_screenInfo;
99+
std::mutex m_screenInfoMutex;
91100
std::unordered_set<UTILS::CURL::Cookie> m_cookies;
92101
std::mutex m_cookiesMutex;
93102
adaptive::AdaptiveTree* m_tree{nullptr};

src/common/Chooser.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CHOOSER::IRepresentationChooser::IRepresentationChooser()
8888

8989
void CHOOSER::IRepresentationChooser::OnUpdateScreenRes()
9090
{
91-
const auto sInfo = CSrvBroker::GetResources().GetScreenInfo();
91+
const auto& sInfo = CSrvBroker::GetResources().GetScreenInfo();
9292

9393
LOG::Log(LOGINFO,
9494
"[Repr. chooser] Resolution set: %dx%d, max allowed: %dx%d, Adjust refresh rate: %i",

src/test/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ add_executable(${BINARY}
5353
../utils/XMLUtils.cpp
5454
)
5555

56-
if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
57-
SET(ADD_LINK_LIBS "atomic")
58-
endif()
59-
60-
target_link_libraries(${BINARY} PRIVATE ${BENTO4_LIBRARIES} ${PUGIXML_LIBRARIES} ${GTEST_LIBRARIES} Threads::Threads ${CMAKE_DL_LIBS} ${ADD_LINK_LIBS})
56+
target_link_libraries(${BINARY} PRIVATE ${BENTO4_LIBRARIES} ${PUGIXML_LIBRARIES} ${GTEST_LIBRARIES} Threads::Threads ${CMAKE_DL_LIBS})
6157

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

0 commit comments

Comments
 (0)