blob: b2fe7acfc406458b865abc759fa917ebfaaf3083 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.org1b1cd782012-06-28 06:34:08 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.orgf5d4cb12013-05-17 13:44:48 +000011#include "webrtc/video_engine/vie_ref_count.h"
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000012
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000013#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000014
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000015namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000016
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000017ViERefCount::ViERefCount()
18 : count_(0),
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000019 crit_(CriticalSectionWrapper::CreateCriticalSection()) {
niklase@google.com470e71d2011-07-07 08:21:25 +000020}
21
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000022ViERefCount::~ViERefCount() {
niklase@google.com470e71d2011-07-07 08:21:25 +000023}
24
mflodman@webrtc.org1b1cd782012-06-28 06:34:08 +000025ViERefCount& ViERefCount::operator++(int) { // NOLINT
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000026 CriticalSectionScoped lock(crit_.get());
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000027 count_++;
28 return *this;
niklase@google.com470e71d2011-07-07 08:21:25 +000029}
30
mflodman@webrtc.org1b1cd782012-06-28 06:34:08 +000031ViERefCount& ViERefCount::operator--(int) { // NOLINT
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000032 CriticalSectionScoped lock(crit_.get());
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000033 count_--;
34 return *this;
niklase@google.com470e71d2011-07-07 08:21:25 +000035}
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000036
37void ViERefCount::Reset() {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000038 CriticalSectionScoped lock(crit_.get());
mflodman@webrtc.orgffabb592011-11-29 17:31:21 +000039 count_ = 0;
40}
41
42int ViERefCount::GetCount() const {
43 return count_;
44}
45
46} // namespace webrtc