Index: webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
index e6087f112396027226763a6353d7e4adffa33ee3..dc0935a4a36ea3f7da43edee2b753c360f8b4e6a 100644 |
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_magnifier.cc |
@@ -12,6 +12,7 @@ |
#include <assert.h> |
+#include "webrtc/base/atomicops.h" |
#include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
#include "webrtc/modules/desktop_capture/desktop_frame.h" |
#include "webrtc/modules/desktop_capture/desktop_frame_win.h" |
@@ -33,7 +34,7 @@ static LPCTSTR kHostWindowName = L"MagnifierHost"; |
static LPCTSTR kMagnifierWindowClass = L"Magnifier"; |
static LPCTSTR kMagnifierWindowName = L"MagnifierWindow"; |
-Atomic32 ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES); |
+volatile int ScreenCapturerWinMagnifier::tls_index_(TLS_OUT_OF_INDEXES); |
ScreenCapturerWinMagnifier::ScreenCapturerWinMagnifier( |
rtc::scoped_ptr<ScreenCapturer> fallback_capturer) |
@@ -236,11 +237,11 @@ BOOL ScreenCapturerWinMagnifier::OnMagImageScalingCallback( |
RECT unclipped, |
RECT clipped, |
HRGN dirty) { |
- assert(tls_index_.Value() != TLS_OUT_OF_INDEXES); |
+ assert(rtc::AtomicOps::AcquireLoad(&tls_index_) != TLS_OUT_OF_INDEXES); |
ScreenCapturerWinMagnifier* owner = |
reinterpret_cast<ScreenCapturerWinMagnifier*>( |
- TlsGetValue(tls_index_.Value())); |
+ TlsGetValue(rtc::AtomicOps::AcquireLoad(&tls_index_))); |
owner->OnCaptured(srcdata, srcheader); |
@@ -369,16 +370,19 @@ bool ScreenCapturerWinMagnifier::InitializeMagnifier() { |
} |
} |
- if (tls_index_.Value() == TLS_OUT_OF_INDEXES) { |
+ if (rtc::AtomicOps::AcquireLoad(&tls_index_) == TLS_OUT_OF_INDEXES) { |
// More than one threads may get here at the same time, but only one will |
- // write to tls_index_ using CompareExchange. |
+ // write to tls_index_ using CompareAndSwap. |
DWORD new_tls_index = TlsAlloc(); |
- if (!tls_index_.CompareExchange(new_tls_index, TLS_OUT_OF_INDEXES)) |
+ if (rtc::AtomicOps::CompareAndSwap(&tls_index_, TLS_OUT_OF_INDEXES, |
+ new_tls_index) != TLS_OUT_OF_INDEXES) { |
+ // Another thread allocated TLS before us, remove additional allocation. |
TlsFree(new_tls_index); |
+ } |
} |
- assert(tls_index_.Value() != TLS_OUT_OF_INDEXES); |
- TlsSetValue(tls_index_.Value(), this); |
+ assert(rtc::AtomicOps::AcquireLoad(&tls_index_) != TLS_OUT_OF_INDEXES); |
+ TlsSetValue(rtc::AtomicOps::AcquireLoad(&tls_index_), this); |
magnifier_initialized_ = true; |
return true; |