Let ChanneOwner use scoped_refptr and RefCountedBase.
Eliminates manual reference counting logic, and one of the few remaining uses of the Atomic32 type. Bug: webrtc:8270 Change-Id: Ibbbf227c710f7e8f68a98bac46d3e24b7cb5ee2f Reviewed-on: https://webrtc-review.googlesource.com/14600 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#20393}
This commit is contained in:
parent
d92e0b5923
commit
f92d871f4f
@ -58,6 +58,7 @@ rtc_static_library("voice_engine") {
|
||||
"../api:call_api",
|
||||
"../api:libjingle_peerconnection_api",
|
||||
"../api:optional",
|
||||
"../api:refcountedbase",
|
||||
"../api:transport_api",
|
||||
"../api/audio_codecs:audio_codecs_api",
|
||||
"../api/audio_codecs:builtin_audio_decoder_factory",
|
||||
|
||||
@ -19,31 +19,8 @@ namespace voe {
|
||||
ChannelOwner::ChannelOwner(class Channel* channel)
|
||||
: channel_ref_(new ChannelRef(channel)) {}
|
||||
|
||||
ChannelOwner::ChannelOwner(const ChannelOwner& channel_owner)
|
||||
: channel_ref_(channel_owner.channel_ref_) {
|
||||
++channel_ref_->ref_count;
|
||||
}
|
||||
|
||||
ChannelOwner::~ChannelOwner() {
|
||||
if (--channel_ref_->ref_count == 0)
|
||||
delete channel_ref_;
|
||||
}
|
||||
|
||||
ChannelOwner& ChannelOwner::operator=(const ChannelOwner& other) {
|
||||
if (other.channel_ref_ == channel_ref_)
|
||||
return *this;
|
||||
|
||||
if (--channel_ref_->ref_count == 0)
|
||||
delete channel_ref_;
|
||||
|
||||
channel_ref_ = other.channel_ref_;
|
||||
++channel_ref_->ref_count;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChannelOwner::ChannelRef::ChannelRef(class Channel* channel)
|
||||
: channel(channel), ref_count(1) {}
|
||||
: channel(channel) {}
|
||||
|
||||
ChannelManager::ChannelManager(uint32_t instance_id)
|
||||
: instance_id_(instance_id),
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "api/refcountedbase.h"
|
||||
#include "rtc_base/constructormagic.h"
|
||||
#include "rtc_base/criticalsection.h"
|
||||
#include "rtc_base/random.h"
|
||||
@ -49,26 +50,24 @@ class Channel;
|
||||
class ChannelOwner {
|
||||
public:
|
||||
explicit ChannelOwner(Channel* channel);
|
||||
ChannelOwner(const ChannelOwner& channel_owner);
|
||||
ChannelOwner(const ChannelOwner& channel_owner) = default;
|
||||
|
||||
~ChannelOwner();
|
||||
~ChannelOwner() = default;
|
||||
|
||||
ChannelOwner& operator=(const ChannelOwner& other);
|
||||
ChannelOwner& operator=(const ChannelOwner& other) = default;
|
||||
|
||||
Channel* channel() const { return channel_ref_->channel.get(); }
|
||||
bool IsValid() { return channel_ref_->channel.get() != NULL; }
|
||||
int use_count() const { return channel_ref_->ref_count.Value(); }
|
||||
private:
|
||||
// Shared instance of a Channel. Copying ChannelOwners increase the reference
|
||||
// count and destroying ChannelOwners decrease references. Channels are
|
||||
// deleted when no references to them are held.
|
||||
struct ChannelRef {
|
||||
struct ChannelRef : public rtc::RefCountedBase {
|
||||
ChannelRef(Channel* channel);
|
||||
const std::unique_ptr<Channel> channel;
|
||||
Atomic32 ref_count;
|
||||
};
|
||||
|
||||
ChannelRef* channel_ref_;
|
||||
rtc::scoped_refptr<ChannelRef> channel_ref_;
|
||||
};
|
||||
|
||||
class ChannelManager {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user