diff --git a/talk/session/media/srtpfilter.cc b/talk/session/media/srtpfilter.cc index fdc379e571..4a54740cef 100644 --- a/talk/session/media/srtpfilter.cc +++ b/talk/session/media/srtpfilter.cc @@ -484,7 +484,7 @@ bool SrtpFilter::ParseKeyParams(const std::string& key_params, bool SrtpSession::inited_ = false; // This lock protects SrtpSession::inited_ and SrtpSession::sessions_. -rtc::GlobalLockPod SrtpSession::lock_ = {{0}}; +rtc::GlobalLockPod SrtpSession::lock_; SrtpSession::SrtpSession() : session_(NULL), diff --git a/webrtc/base/atomicops.h b/webrtc/base/atomicops.h index 42b87097df..188cd3f189 100644 --- a/webrtc/base/atomicops.h +++ b/webrtc/base/atomicops.h @@ -21,7 +21,6 @@ #endif // defined(WEBRTC_WIN) namespace rtc { - class AtomicOps { public: #if defined(WEBRTC_WIN) @@ -81,50 +80,8 @@ class AtomicOps { #endif }; -// POD struct version of AtomicOps, prevents accidental non-atomic operator -// usage (such as ++, -- or =). Functions are static, so that the AtomicInt:: -// prefix must be present in the code, clearly labeling the operations as -// atomic. -// Do not copy-initialize, since that performs non-atomic reads of value_. The -// copy constructor needs to be present for brace initialization. -struct AtomicInt { - AtomicInt() = delete; - // TODO(pbos): When MSVC allows brace initialization (or we move to - // std::atomic), remove copy constructor (or have it implicitly removed by - // std::atomic). - void operator=(const AtomicInt&) = delete; - // value_ is public to permit brace initialization. Should not be accessed - // directly. - volatile int value_; - // Atomically increments |i|, returns the resulting incremented value. - static int Increment(AtomicInt* i) { - return AtomicOps::Increment(&i->value_); - } - - // Atomically decrements |i|, returns the resulting decremented value. - static int Decrement(AtomicInt* i) { - return AtomicOps::Decrement(&i->value_); - } - - // Atomically loads |i|. - static int AcquireLoad(const AtomicInt* i) { - return AtomicOps::AcquireLoad(&i->value_); - } - - // Atomically stores |value| in |i|. - static void ReleaseStore(AtomicInt* i, int value) { - AtomicOps::ReleaseStore(&i->value_, value); - } - - // Attempts to compare-and-swaps |old_value| for |new_value| in |i| , returns - // |i|'s initial value. If equal to |old_value|, then the CAS succeeded, - // otherwise no operation is performed. - static int CompareAndSwap(AtomicInt* i, int old_value, int new_value) { - return AtomicOps::CompareAndSwap(&i->value_, old_value, new_value); - } -}; } #endif // WEBRTC_BASE_ATOMICOPS_H_ diff --git a/webrtc/base/criticalsection.cc b/webrtc/base/criticalsection.cc index 97322f45c9..1f50c2355d 100644 --- a/webrtc/base/criticalsection.cc +++ b/webrtc/base/criticalsection.cc @@ -139,7 +139,7 @@ void GlobalLockPod::Lock() { const struct timespec ts_null = {0}; #endif - while (AtomicInt::CompareAndSwap(&lock_acquired, 0, 1)) { + while (AtomicOps::CompareAndSwap(&lock_acquired, 0, 1)) { #if defined(WEBRTC_WIN) ::Sleep(0); #else @@ -149,13 +149,16 @@ void GlobalLockPod::Lock() { } void GlobalLockPod::Unlock() { - int old_value = AtomicInt::CompareAndSwap(&lock_acquired, 1, 0); + int old_value = AtomicOps::CompareAndSwap(&lock_acquired, 1, 0); RTC_DCHECK_EQ(1, old_value) << "Unlock called without calling Lock first"; } -GlobalLock::GlobalLock() : GlobalLockPod({{0}}) {} +GlobalLock::GlobalLock() { + lock_acquired = 0; +} -GlobalLockScope::GlobalLockScope(GlobalLockPod* lock) : lock_(lock) { +GlobalLockScope::GlobalLockScope(GlobalLockPod* lock) + : lock_(lock) { lock_->Lock(); } diff --git a/webrtc/base/criticalsection.h b/webrtc/base/criticalsection.h index ed3998b678..ddbf857f2b 100644 --- a/webrtc/base/criticalsection.h +++ b/webrtc/base/criticalsection.h @@ -106,7 +106,7 @@ class LOCKABLE GlobalLockPod { void Unlock() UNLOCK_FUNCTION(); - AtomicInt lock_acquired; + volatile int lock_acquired; }; class GlobalLock : public GlobalLockPod { diff --git a/webrtc/base/refcount.h b/webrtc/base/refcount.h index f655602ab8..55ce23a348 100644 --- a/webrtc/base/refcount.h +++ b/webrtc/base/refcount.h @@ -29,128 +29,78 @@ class RefCountInterface { template class RefCountedObject : public T { public: - RefCountedObject() : ref_count_({0}) {} + RefCountedObject() : ref_count_(0) { + } - template - explicit RefCountedObject(P p) - : T(p), ref_count_({0}) {} + template + explicit RefCountedObject(P p) : T(p), ref_count_(0) { + } - template - RefCountedObject(P1 p1, P2 p2) - : T(p1, p2), ref_count_({0}) {} + template + RefCountedObject(P1 p1, P2 p2) : T(p1, p2), ref_count_(0) { + } - template - RefCountedObject(P1 p1, P2 p2, P3 p3) - : T(p1, p2, p3), ref_count_({0}) {} + template + RefCountedObject(P1 p1, P2 p2, P3 p3) : T(p1, p2, p3), ref_count_(0) { + } - template + template RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4) - : T(p1, p2, p3, p4), ref_count_({0}) {} + : T(p1, p2, p3, p4), ref_count_(0) { + } - template + template RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) - : T(p1, p2, p3, p4, p5), ref_count_({0}) {} + : T(p1, p2, p3, p4, p5), ref_count_(0) { + } - template + template RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6) - : T(p1, p2, p3, p4, p5, p6), ref_count_({0}) {} + : T(p1, p2, p3, p4, p5, p6), ref_count_(0) { + } - template + template RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7) - : T(p1, p2, p3, p4, p5, p6, p7), ref_count_({0}) {} + : T(p1, p2, p3, p4, p5, p6, p7), ref_count_(0) { + } - template + template RefCountedObject(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8) - : T(p1, p2, p3, p4, p5, p6, p7, p8), ref_count_({0}) {} + : T(p1, p2, p3, p4, p5, p6, p7, p8), ref_count_(0) { + } - template - RefCountedObject(P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7, - P8 p8, - P9 p9) - : T(p1, p2, p3, p4, p5, p6, p7, p8, p9), ref_count_({0}) {} + template + RefCountedObject( + P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9) + : T(p1, p2, p3, p4, p5, p6, p7, p8, p9), ref_count_(0) { + } - template - RefCountedObject(P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7, - P8 p8, - P9 p9, - P10 p10) - : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10), ref_count_({0}) {} + template + RefCountedObject( + P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10) + : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10), ref_count_(0) { + } - template - RefCountedObject(P1 p1, - P2 p2, - P3 p3, - P4 p4, - P5 p5, - P6 p6, - P7 p7, - P8 p8, - P9 p9, - P10 p10, - P11 p11) - : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11), ref_count_({0}) {} + template + RefCountedObject( + P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8, P9 p9, P10 p10, + P11 p11) + : T(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11), ref_count_(0) { + } - virtual int AddRef() const { return AtomicInt::Increment(&ref_count_); } + virtual int AddRef() const { + return AtomicOps::Increment(&ref_count_); + } virtual int Release() const { - int count = AtomicInt::Decrement(&ref_count_); + int count = AtomicOps::Decrement(&ref_count_); if (!count) { delete this; } @@ -164,14 +114,14 @@ class RefCountedObject : public T { // barrier needed for the owning thread to act on the object, knowing that it // has exclusive access to the object. virtual bool HasOneRef() const { - return AtomicInt::AcquireLoad(&ref_count_) == 1; + return AtomicOps::AcquireLoad(&ref_count_) == 1; } protected: virtual ~RefCountedObject() { } - mutable AtomicInt ref_count_; + mutable volatile int ref_count_; }; } // namespace rtc diff --git a/webrtc/modules/audio_device/ios/audio_device_ios.h b/webrtc/modules/audio_device/ios/audio_device_ios.h index 1bac27dd6b..c4eb0d6f64 100644 --- a/webrtc/modules/audio_device/ios/audio_device_ios.h +++ b/webrtc/modules/audio_device/ios/audio_device_ios.h @@ -13,7 +13,6 @@ #include -#include "webrtc/base/atomicops.h" #include "webrtc/base/scoped_ptr.h" #include "webrtc/base/thread_checker.h" #include "webrtc/modules/audio_device/audio_device_generic.h" @@ -54,15 +53,11 @@ class AudioDeviceIOS : public AudioDeviceGeneric { int32_t StartPlayout() override; int32_t StopPlayout() override; - bool Playing() const override { - return rtc::AtomicInt::AcquireLoad(&playing_) != 0; - } + bool Playing() const override { return playing_; } int32_t StartRecording() override; int32_t StopRecording() override; - bool Recording() const override { - return rtc::AtomicInt::AcquireLoad(&recording_) != 0; - } + bool Recording() const override { return recording_; } int32_t SetLoudspeakerStatus(bool enable) override; int32_t GetLoudspeakerStatus(bool& enabled) const override; @@ -276,10 +271,10 @@ class AudioDeviceIOS : public AudioDeviceGeneric { rtc::scoped_ptr record_audio_buffer_; // Set to 1 when recording is active and 0 otherwise. - rtc::AtomicInt recording_; + volatile int recording_; // Set to 1 when playout is active and 0 otherwise. - rtc::AtomicInt playing_; + volatile int playing_; // Set to true after successful call to Init(), false otherwise. bool initialized_; diff --git a/webrtc/modules/audio_device/ios/audio_device_ios.mm b/webrtc/modules/audio_device/ios/audio_device_ios.mm index 95834d2531..b0d26be6ec 100644 --- a/webrtc/modules/audio_device/ios/audio_device_ios.mm +++ b/webrtc/modules/audio_device/ios/audio_device_ios.mm @@ -28,7 +28,7 @@ namespace webrtc { // Protects |g_audio_session_users|. -static rtc::GlobalLockPod g_lock = {{0}}; +static rtc::GlobalLockPod g_lock; // Counts number of users (=instances of this object) who needs an active // audio session. This variable is used to ensure that we only activate an audio @@ -288,8 +288,8 @@ static void LogDeviceInfo() { AudioDeviceIOS::AudioDeviceIOS() : audio_device_buffer_(nullptr), vpio_unit_(nullptr), - recording_({0}), - playing_({0}), + recording_(0), + playing_(0), initialized_(false), rec_is_initialized_(false), play_is_initialized_(false), @@ -359,7 +359,7 @@ int32_t AudioDeviceIOS::InitPlayout() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(initialized_); RTC_DCHECK(!play_is_initialized_); - RTC_DCHECK(!Playing()); + RTC_DCHECK(!playing_); if (!rec_is_initialized_) { if (!InitPlayOrRecord()) { LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitPlayout!"; @@ -375,7 +375,7 @@ int32_t AudioDeviceIOS::InitRecording() { RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(initialized_); RTC_DCHECK(!rec_is_initialized_); - RTC_DCHECK(!Recording()); + RTC_DCHECK(!recording_); if (!play_is_initialized_) { if (!InitPlayOrRecord()) { LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitRecording!"; @@ -390,9 +390,9 @@ int32_t AudioDeviceIOS::StartPlayout() { LOGI() << "StartPlayout"; RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(play_is_initialized_); - RTC_DCHECK(!Playing()); + RTC_DCHECK(!playing_); fine_audio_buffer_->ResetPlayout(); - if (!Recording()) { + if (!recording_) { OSStatus result = AudioOutputUnitStart(vpio_unit_); if (result != noErr) { LOG_F(LS_ERROR) << "AudioOutputUnitStart failed for StartPlayout: " @@ -401,21 +401,21 @@ int32_t AudioDeviceIOS::StartPlayout() { } LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started"; } - rtc::AtomicInt::ReleaseStore(&playing_, 1); + rtc::AtomicOps::ReleaseStore(&playing_, 1); return 0; } int32_t AudioDeviceIOS::StopPlayout() { LOGI() << "StopPlayout"; RTC_DCHECK(thread_checker_.CalledOnValidThread()); - if (!play_is_initialized_ || !Playing()) { + if (!play_is_initialized_ || !playing_) { return 0; } - if (!Recording()) { + if (!recording_) { ShutdownPlayOrRecord(); } play_is_initialized_ = false; - rtc::AtomicInt::ReleaseStore(&playing_, 0); + rtc::AtomicOps::ReleaseStore(&playing_, 0); return 0; } @@ -423,9 +423,9 @@ int32_t AudioDeviceIOS::StartRecording() { LOGI() << "StartRecording"; RTC_DCHECK(thread_checker_.CalledOnValidThread()); RTC_DCHECK(rec_is_initialized_); - RTC_DCHECK(!Recording()); + RTC_DCHECK(!recording_); fine_audio_buffer_->ResetRecord(); - if (!Playing()) { + if (!playing_) { OSStatus result = AudioOutputUnitStart(vpio_unit_); if (result != noErr) { LOG_F(LS_ERROR) << "AudioOutputUnitStart failed for StartRecording: " @@ -434,21 +434,21 @@ int32_t AudioDeviceIOS::StartRecording() { } LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started"; } - rtc::AtomicInt::ReleaseStore(&recording_, 1); + rtc::AtomicOps::ReleaseStore(&recording_, 1); return 0; } int32_t AudioDeviceIOS::StopRecording() { LOGI() << "StopRecording"; RTC_DCHECK(thread_checker_.CalledOnValidThread()); - if (!rec_is_initialized_ || !Recording()) { + if (!rec_is_initialized_ || !recording_) { return 0; } - if (!Playing()) { + if (!playing_) { ShutdownPlayOrRecord(); } rec_is_initialized_ = false; - rtc::AtomicInt::ReleaseStore(&recording_, 0); + rtc::AtomicOps::ReleaseStore(&recording_, 0); return 0; } @@ -1028,7 +1028,7 @@ OSStatus AudioDeviceIOS::OnRecordedDataIsAvailable( UInt32 in_number_frames) { OSStatus result = noErr; // Simply return if recording is not enabled. - if (!Recording()) + if (!rtc::AtomicOps::AcquireLoad(&recording_)) return result; if (in_number_frames != record_parameters_.frames_per_buffer()) { // We have seen short bursts (1-2 frames) where |in_number_frames| changes. @@ -1087,7 +1087,7 @@ OSStatus AudioDeviceIOS::OnGetPlayoutData( SInt8* destination = static_cast(io_data->mBuffers[0].mData); // Produce silence and give audio unit a hint about it if playout is not // activated. - if (!Playing()) { + if (!rtc::AtomicOps::AcquireLoad(&playing_)) { *io_action_flags |= kAudioUnitRenderAction_OutputIsSilence; memset(destination, 0, dataSizeInBytes); return noErr; diff --git a/webrtc/modules/pacing/packet_router.cc b/webrtc/modules/pacing/packet_router.cc index 301585fb96..5fd350834a 100644 --- a/webrtc/modules/pacing/packet_router.cc +++ b/webrtc/modules/pacing/packet_router.cc @@ -18,7 +18,8 @@ namespace webrtc { -PacketRouter::PacketRouter() : transport_seq_({0}) {} +PacketRouter::PacketRouter() : transport_seq_(0) { +} PacketRouter::~PacketRouter() { RTC_DCHECK(rtp_modules_.empty()); @@ -68,11 +69,11 @@ size_t PacketRouter::TimeToSendPadding(size_t bytes_to_send) { } void PacketRouter::SetTransportWideSequenceNumber(uint16_t sequence_number) { - rtc::AtomicInt::ReleaseStore(&transport_seq_, sequence_number); + rtc::AtomicOps::ReleaseStore(&transport_seq_, sequence_number); } uint16_t PacketRouter::AllocateSequenceNumber() { - int prev_seq = rtc::AtomicInt::AcquireLoad(&transport_seq_); + int prev_seq = rtc::AtomicOps::AcquireLoad(&transport_seq_); int desired_prev_seq; int new_seq; do { @@ -82,7 +83,7 @@ uint16_t PacketRouter::AllocateSequenceNumber() { // time the CAS operation was executed. Thus, if prev_seq is returned, the // operation was successful - otherwise we need to retry. Saving the // return value saves us a load on retry. - prev_seq = rtc::AtomicInt::CompareAndSwap(&transport_seq_, desired_prev_seq, + prev_seq = rtc::AtomicOps::CompareAndSwap(&transport_seq_, desired_prev_seq, new_seq); } while (prev_seq != desired_prev_seq); diff --git a/webrtc/modules/pacing/packet_router.h b/webrtc/modules/pacing/packet_router.h index 50913b5df2..edef1aa9b3 100644 --- a/webrtc/modules/pacing/packet_router.h +++ b/webrtc/modules/pacing/packet_router.h @@ -13,7 +13,6 @@ #include -#include "webrtc/base/atomicops.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/scoped_ptr.h" @@ -59,7 +58,7 @@ class PacketRouter : public PacedSender::Callback, // Map from ssrc to sending rtp module. std::list rtp_modules_ GUARDED_BY(modules_lock_); - rtc::AtomicInt transport_seq_; + volatile int transport_seq_; RTC_DISALLOW_COPY_AND_ASSIGN(PacketRouter); }; diff --git a/webrtc/system_wrappers/include/trace.h b/webrtc/system_wrappers/include/trace.h index 6b401e87cd..25a3d746c4 100644 --- a/webrtc/system_wrappers/include/trace.h +++ b/webrtc/system_wrappers/include/trace.h @@ -16,7 +16,6 @@ #ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ #define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TRACE_H_ -#include "webrtc/base/atomicops.h" #include "webrtc/common_types.h" #include "webrtc/typedefs.h" @@ -85,7 +84,7 @@ class Trace { const char* msg, ...); private: - static rtc::AtomicInt level_filter_; + static volatile int level_filter_; }; } // namespace webrtc diff --git a/webrtc/system_wrappers/source/trace_impl.cc b/webrtc/system_wrappers/source/trace_impl.cc index 3bf1f1bb64..5029f5ab6e 100644 --- a/webrtc/system_wrappers/source/trace_impl.cc +++ b/webrtc/system_wrappers/source/trace_impl.cc @@ -34,7 +34,7 @@ namespace webrtc { const int Trace::kBoilerplateLength = 71; const int Trace::kTimestampPosition = 13; const int Trace::kTimestampLength = 12; -rtc::AtomicInt Trace::level_filter_ = {kTraceDefault}; +volatile int Trace::level_filter_ = kTraceDefault; // Construct On First Use idiom. Avoids "static initialization order fiasco". TraceImpl* TraceImpl::StaticInstance(CountOperation count_operation, @@ -548,12 +548,12 @@ int32_t Trace::TraceFile(char file_name[FileWrapper::kMaxFileNameSize]) { // static void Trace::set_level_filter(int filter) { - rtc::AtomicInt::ReleaseStore(&level_filter_, filter); + rtc::AtomicOps::ReleaseStore(&level_filter_, filter); } // static int Trace::level_filter() { - return rtc::AtomicInt::AcquireLoad(&level_filter_); + return rtc::AtomicOps::AcquireLoad(&level_filter_); } // static diff --git a/webrtc/video/video_capture_input.cc b/webrtc/video/video_capture_input.cc index eaacf72a83..ac05e36c40 100644 --- a/webrtc/video/video_capture_input.cc +++ b/webrtc/video/video_capture_input.cc @@ -44,7 +44,7 @@ VideoCaptureInput::VideoCaptureInput( incoming_frame_cs_(CriticalSectionWrapper::CreateCriticalSection()), encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), capture_event_(EventWrapper::Create()), - stop_({0}), + stop_(0), last_captured_timestamp_(0), delta_ntp_internal_ms_( Clock::GetRealTimeClock()->CurrentNtpInMilliseconds() - @@ -63,7 +63,7 @@ VideoCaptureInput::~VideoCaptureInput() { module_process_thread_->DeRegisterModule(overuse_detector_.get()); // Stop the thread. - rtc::AtomicInt::ReleaseStore(&stop_, 1); + rtc::AtomicOps::ReleaseStore(&stop_, 1); capture_event_->Set(); encoder_thread_.Stop(); } @@ -127,7 +127,7 @@ bool VideoCaptureInput::EncoderProcess() { static const int kThreadWaitTimeMs = 100; int64_t capture_time = -1; if (capture_event_->Wait(kThreadWaitTimeMs) == kEventSignaled) { - if (rtc::AtomicInt::AcquireLoad(&stop_)) + if (rtc::AtomicOps::AcquireLoad(&stop_)) return false; int64_t encode_start_time = -1; diff --git a/webrtc/video/video_capture_input.h b/webrtc/video/video_capture_input.h index b76c929c21..9a5aae3227 100644 --- a/webrtc/video/video_capture_input.h +++ b/webrtc/video/video_capture_input.h @@ -13,7 +13,6 @@ #include -#include "webrtc/base/atomicops.h" #include "webrtc/base/criticalsection.h" #include "webrtc/base/platform_thread.h" #include "webrtc/base/scoped_ptr.h" @@ -82,7 +81,7 @@ class VideoCaptureInput : public webrtc::VideoCaptureInput { rtc::PlatformThread encoder_thread_; rtc::scoped_ptr capture_event_; - rtc::AtomicInt stop_; + volatile int stop_; VideoFrame captured_frame_ GUARDED_BY(capture_cs_.get()); // Used to make sure incoming time stamp is increasing for every frame.