Chromium Code Reviews| Index: webrtc/base/atomicops.h |
| diff --git a/webrtc/base/atomicops.h b/webrtc/base/atomicops.h |
| index a863566a670aad0b3d4904f0040c3c20ad845461..573db7f9ddc74f21c34f9fadc185ac837901d0f5 100644 |
| --- a/webrtc/base/atomicops.h |
| +++ b/webrtc/base/atomicops.h |
| @@ -11,6 +11,8 @@ |
| #ifndef WEBRTC_BASE_ATOMICOPS_H_ |
| #define WEBRTC_BASE_ATOMICOPS_H_ |
| +#include "webrtc/base/constructormagic.h" |
| + |
| #if defined(WEBRTC_WIN) |
| // Include winsock2.h before including <windows.h> to maintain consistency with |
| // win32.h. We can't include win32.h directly here since it pulls in |
| @@ -21,6 +23,7 @@ |
| #endif // defined(WEBRTC_WIN) |
| namespace rtc { |
| + |
| class AtomicOps { |
| public: |
| #if defined(WEBRTC_WIN) |
| @@ -61,8 +64,34 @@ class AtomicOps { |
| #endif |
| }; |
| +// POD struct version of AtomicOps, prevents accidental non-atomic usage (such |
| +// as ++, =, reads or writes). Operations are still explicit to not hide that |
| +// the operations are atomic. |
|
kwiberg-webrtc
2015/11/02 12:41:49
Maybe "Functions are static, so that the AtomicInt
pbos-webrtc
2015/11/02 15:21:15
Done, yep that's the plan. I'm not sure if that sh
|
| +struct AtomicInt { |
| + AtomicInt() = delete; |
| + // value_ is public to permit brace initialization. Should not be accessed |
| + // directly. |
| + volatile int value_; |
| + static int Increment(AtomicInt* i) { |
| + return AtomicOps::Increment(&i->value_); |
| + } |
| + static int Decrement(AtomicInt* i) { |
| + return AtomicOps::Decrement(&i->value_); |
| + } |
| + static int AcquireLoad(const AtomicInt* i) { |
| + return AtomicOps::AcquireLoad(&i->value_); |
| + } |
| + static void ReleaseStore(AtomicInt* i, int value) { |
| + AtomicOps::ReleaseStore(&i->value_, value); |
| + } |
| + static int CompareAndSwap(AtomicInt* i, int old_value, int new_value) { |
| + return AtomicOps::CompareAndSwap(&i->value_, old_value, new_value); |
| + } |
|
kwiberg-webrtc
2015/11/02 12:41:50
I'd like a short comment on each of these, explain
pbos-webrtc
2015/11/02 15:21:15
Done.
|
| + |
| + RTC_DISALLOW_COPY_AND_ASSIGN(AtomicInt); |
| +}; |
| } |
| #endif // WEBRTC_BASE_ATOMICOPS_H_ |