Refactored ViERefCount.

In a coming CL: Use ref count in system_wrappers instead of this class.

Review URL: http://webrtc-codereview.appspot.com/291010

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1051 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mflodman@webrtc.org 2011-11-29 17:31:21 +00:00
parent fc9b903fbe
commit ffabb59f6e
2 changed files with 46 additions and 58 deletions

View File

@ -8,51 +8,40 @@
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* ViERefCount.cpp
*/
#include "vie_ref_count.h"
#include "critical_section_wrapper.h"
namespace webrtc {
ViERefCount::ViERefCount() :
_count(0),
_crit(*webrtc::CriticalSectionWrapper::CreateCriticalSection())
{
ViERefCount::ViERefCount()
: count_(0),
crit_(*webrtc::CriticalSectionWrapper::CreateCriticalSection()) {
}
ViERefCount::~ViERefCount()
{
delete &_crit;
ViERefCount::~ViERefCount() {
delete &crit_;
}
ViERefCount&
ViERefCount::operator++(int)
{
webrtc::CriticalSectionScoped lock(_crit);
_count++;
return *this;
}
ViERefCount&
ViERefCount::operator--(int)
{
webrtc::CriticalSectionScoped lock(_crit);
_count--;
return *this;
}
void
ViERefCount::Reset()
{
webrtc::CriticalSectionScoped lock(_crit);
_count = 0;
ViERefCount& ViERefCount::operator++(int) {
CriticalSectionScoped lock(crit_);
count_++;
return *this;
}
int
ViERefCount::GetCount() const
{
return _count;
ViERefCount& ViERefCount::operator--(int) {
CriticalSectionScoped lock(crit_);
count_--;
return *this;
}
void ViERefCount::Reset() {
CriticalSectionScoped lock(crit_);
count_ = 0;
}
int ViERefCount::GetCount() const {
return count_;
}
} // namespace webrtc

View File

@ -8,32 +8,31 @@
* be found in the AUTHORS file in the root of the source tree.
*/
/*
* vie_ref_count.h
*/
// TODO(mflodman) Use ref count class in system_wrappers.
#ifndef WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_REF_COUNT_H_
#define WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_REF_COUNT_H_
#ifndef WEBRTC_VIDEO_ENGINE_VIE_REF_COUNT_H_
#define WEBRTC_VIDEO_ENGINE_VIE_REF_COUNT_H_
namespace webrtc {
class CriticalSectionWrapper;
}
class ViERefCount
{
public:
ViERefCount();
~ViERefCount();
ViERefCount& operator++(int);
ViERefCount& operator--(int);
void Reset();
int GetCount() const;
class ViERefCount {
public:
ViERefCount();
~ViERefCount();
private:
volatile int _count;
webrtc::CriticalSectionWrapper& _crit;
ViERefCount& operator++(int);
ViERefCount& operator--(int);
void Reset();
int GetCount() const;
private:
volatile int count_;
webrtc::CriticalSectionWrapper& crit_;
};
#endif // WEBRTC_VIDEO_ENGINE_MAIN_SOURCE_VIE_REF_COUNT_H_
} // namespace webrtc
#endif // WEBRTC_VIDEO_ENGINE_VIE_REF_COUNT_H_