OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/voice_engine/channel_manager.h" | 11 #include "webrtc/voice_engine/channel_manager.h" |
12 | 12 |
| 13 #include "webrtc/base/atomicops.h" |
13 #include "webrtc/common.h" | 14 #include "webrtc/common.h" |
14 #include "webrtc/voice_engine/channel.h" | 15 #include "webrtc/voice_engine/channel.h" |
15 | 16 |
16 namespace webrtc { | 17 namespace webrtc { |
17 namespace voe { | 18 namespace voe { |
18 | 19 |
19 ChannelOwner::ChannelOwner(class Channel* channel) | 20 ChannelOwner::ChannelOwner(class Channel* channel) |
20 : channel_ref_(new ChannelRef(channel)) {} | 21 : channel_ref_(new ChannelRef(channel)) {} |
21 | 22 |
22 ChannelOwner::ChannelOwner(const ChannelOwner& channel_owner) | 23 ChannelOwner::ChannelOwner(const ChannelOwner& channel_owner) |
23 : channel_ref_(channel_owner.channel_ref_) { | 24 : channel_ref_(channel_owner.channel_ref_) { |
24 ++channel_ref_->ref_count; | 25 rtc::AtomicOps::Increment(&channel_ref_->ref_count); |
25 } | 26 } |
26 | 27 |
27 ChannelOwner::~ChannelOwner() { | 28 ChannelOwner::~ChannelOwner() { |
28 if (--channel_ref_->ref_count == 0) | 29 if (rtc::AtomicOps::Decrement(&channel_ref_->ref_count) == 0) |
29 delete channel_ref_; | 30 delete channel_ref_; |
30 } | 31 } |
31 | 32 |
32 ChannelOwner& ChannelOwner::operator=(const ChannelOwner& other) { | 33 ChannelOwner& ChannelOwner::operator=(const ChannelOwner& other) { |
33 if (other.channel_ref_ == channel_ref_) | 34 if (other.channel_ref_ == channel_ref_) |
34 return *this; | 35 return *this; |
35 | 36 |
36 if (--channel_ref_->ref_count == 0) | 37 if (rtc::AtomicOps::Decrement(&channel_ref_->ref_count) == 0) |
37 delete channel_ref_; | 38 delete channel_ref_; |
38 | 39 |
39 channel_ref_ = other.channel_ref_; | 40 channel_ref_ = other.channel_ref_; |
40 ++channel_ref_->ref_count; | 41 rtc::AtomicOps::Increment(&channel_ref_->ref_count); |
41 | 42 |
42 return *this; | 43 return *this; |
43 } | 44 } |
44 | 45 |
45 ChannelOwner::ChannelRef::ChannelRef(class Channel* channel) | 46 ChannelOwner::ChannelRef::ChannelRef(class Channel* channel) |
46 : channel(channel), ref_count(1) {} | 47 : channel(channel), ref_count(1) {} |
47 | 48 |
48 ChannelManager::ChannelManager(uint32_t instance_id, const Config& config) | 49 ChannelManager::ChannelManager(uint32_t instance_id, const Config& config) |
49 : instance_id_(instance_id), | 50 : instance_id_(instance_id), |
50 last_channel_id_(-1), | 51 last_channel_id_(-1), |
51 lock_(CriticalSectionWrapper::CreateCriticalSection()), | 52 lock_(CriticalSectionWrapper::CreateCriticalSection()), |
52 config_(config), | 53 config_(config), |
53 event_log_(RtcEventLog::Create()) {} | 54 event_log_(RtcEventLog::Create()) {} |
54 | 55 |
55 ChannelOwner ChannelManager::CreateChannel() { | 56 ChannelOwner ChannelManager::CreateChannel() { |
56 return CreateChannelInternal(config_); | 57 return CreateChannelInternal(config_); |
57 } | 58 } |
58 | 59 |
59 ChannelOwner ChannelManager::CreateChannel(const Config& external_config) { | 60 ChannelOwner ChannelManager::CreateChannel(const Config& external_config) { |
60 return CreateChannelInternal(external_config); | 61 return CreateChannelInternal(external_config); |
61 } | 62 } |
62 | 63 |
63 ChannelOwner ChannelManager::CreateChannelInternal(const Config& config) { | 64 ChannelOwner ChannelManager::CreateChannelInternal(const Config& config) { |
64 Channel* channel; | 65 Channel* channel; |
65 Channel::CreateChannel(channel, ++last_channel_id_, instance_id_, | 66 Channel::CreateChannel(channel, rtc::AtomicOps::Increment(&last_channel_id_), |
66 event_log_.get(), config); | 67 instance_id_, event_log_.get(), config); |
67 ChannelOwner channel_owner(channel); | 68 ChannelOwner channel_owner(channel); |
68 | 69 |
69 CriticalSectionScoped crit(lock_.get()); | 70 CriticalSectionScoped crit(lock_.get()); |
70 | 71 |
71 channels_.push_back(channel_owner); | 72 channels_.push_back(channel_owner); |
72 | 73 |
73 return channel_owner; | 74 return channel_owner; |
74 } | 75 } |
75 | 76 |
76 ChannelOwner ChannelManager::GetChannel(int32_t channel_id) { | 77 ChannelOwner ChannelManager::GetChannel(int32_t channel_id) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 bool ChannelManager::Iterator::IsValid() { | 149 bool ChannelManager::Iterator::IsValid() { |
149 return iterator_pos_ < channels_.size(); | 150 return iterator_pos_ < channels_.size(); |
150 } | 151 } |
151 | 152 |
152 void ChannelManager::Iterator::Increment() { | 153 void ChannelManager::Iterator::Increment() { |
153 ++iterator_pos_; | 154 ++iterator_pos_; |
154 } | 155 } |
155 | 156 |
156 } // namespace voe | 157 } // namespace voe |
157 } // namespace webrtc | 158 } // namespace webrtc |
OLD | NEW |