Skip to content

Commit

Permalink
Merge pull request #138 from Renardjojo/atomic
Browse files Browse the repository at this point in the history
Use atomic shared ptr instead of deprecated overload
  • Loading branch information
smasherprog authored Oct 7, 2022
2 parents 9db6cb9 + 4e48145 commit 97c5521
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 8 additions & 0 deletions include/internal/SCCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@
namespace SL {
namespace Screen_Capture {
template <typename F, typename M, typename W> struct CaptureData {
#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L
std::atomic<std::shared_ptr<Timer> > FrameTimer;
#else
std::shared_ptr<Timer> FrameTimer;
#endif
F OnNewFrame;
F OnFrameChanged;
#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L
std::atomic<std::shared_ptr<Timer> > MouseTimer;
#else
std::shared_ptr<Timer> MouseTimer;
#endif
M OnMouseChanged;
W getThingsToWatch;
};
Expand Down
8 changes: 8 additions & 0 deletions include/internal/ThreadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ namespace Screen_Capture {
// get a copy of the shared_ptr in a safe way

frameprocessor.Resume();
#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L
auto timer = data->ScreenCaptureData.FrameTimer.load();
#else
auto timer = std::atomic_load(&data->ScreenCaptureData.FrameTimer);
#endif
timer->start();
auto monitors = GetMonitors();
if (isMonitorInsideBounds(monitors, monitor) && !HasMonitorsChanged(startmonitors, monitors)) {
Expand Down Expand Up @@ -145,7 +149,11 @@ namespace Screen_Capture {
}
while (!data->CommonData_.TerminateThreadsEvent) {
// get a copy of the shared_ptr in a safe way
#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L
auto timer = data->WindowCaptureData.FrameTimer.load();
#else
auto timer = std::atomic_load(&data->WindowCaptureData.FrameTimer);
#endif
timer->start();
ret = frameprocessor.ProcessFrame(wnd);
if (ret != DUPL_RETURN_SUCCESS) {
Expand Down
18 changes: 14 additions & 4 deletions src_cpp/ScreenCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,24 @@ class ScreenCaptureManager : public IScreenCaptureManager {

virtual void setFrameChangeInterval(const std::shared_ptr<Timer> &timer) override
{
std::atomic_store(&Thread_Data_->ScreenCaptureData.FrameTimer, timer);
std::atomic_store(&Thread_Data_->WindowCaptureData.FrameTimer, timer);
#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L
Thread_Data_->ScreenCaptureData.FrameTimer.store(timer);
Thread_Data_->WindowCaptureData.FrameTimer.store(timer);
#else
std::atomic_store(&Thread_Data_->ScreenCaptureData.FrameTimer, timer);
std::atomic_store(&Thread_Data_->WindowCaptureData.FrameTimer, timer);
#endif
}

virtual void setMouseChangeInterval(const std::shared_ptr<Timer> &timer) override
{
std::atomic_store(&Thread_Data_->ScreenCaptureData.MouseTimer, timer);
std::atomic_store(&Thread_Data_->WindowCaptureData.MouseTimer, timer);
#if defined(_WIN32) && defined(__cplusplus) && __cplusplus >= 202002L
Thread_Data_->ScreenCaptureData.MouseTimer.store(timer);
Thread_Data_->WindowCaptureData.MouseTimer.store(timer);
#else
std::atomic_store(&Thread_Data_->ScreenCaptureData.MouseTimer, timer);
std::atomic_store(&Thread_Data_->WindowCaptureData.MouseTimer, timer);
#endif
}

virtual void pause() override { Thread_Data_->CommonData_.Paused = true; }
Expand Down

0 comments on commit 97c5521

Please sign in to comment.