niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | 1b1cd78 | 2012-06-28 06:34:08 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 11 | #include "webrtc/video_engine/vie_ref_count.h" |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 13 | #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 14 | |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 15 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 17 | ViERefCount::ViERefCount() |
| 18 | : count_(0), |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 19 | crit_(CriticalSectionWrapper::CreateCriticalSection()) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | } |
| 21 | |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 22 | ViERefCount::~ViERefCount() { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | } |
| 24 | |
mflodman@webrtc.org | 1b1cd78 | 2012-06-28 06:34:08 +0000 | [diff] [blame] | 25 | ViERefCount& ViERefCount::operator++(int) { // NOLINT |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 26 | CriticalSectionScoped lock(crit_.get()); |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 27 | count_++; |
| 28 | return *this; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | } |
| 30 | |
mflodman@webrtc.org | 1b1cd78 | 2012-06-28 06:34:08 +0000 | [diff] [blame] | 31 | ViERefCount& ViERefCount::operator--(int) { // NOLINT |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 32 | CriticalSectionScoped lock(crit_.get()); |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 33 | count_--; |
| 34 | return *this; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | } |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 36 | |
| 37 | void ViERefCount::Reset() { |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 38 | CriticalSectionScoped lock(crit_.get()); |
mflodman@webrtc.org | ffabb59 | 2011-11-29 17:31:21 +0000 | [diff] [blame] | 39 | count_ = 0; |
| 40 | } |
| 41 | |
| 42 | int ViERefCount::GetCount() const { |
| 43 | return count_; |
| 44 | } |
| 45 | |
| 46 | } // namespace webrtc |