Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: webrtc/voice_engine/channel_manager.cc

Issue 1607353002: Swap use of CriticalSectionWrapper with rtc::CriticalSection in voice_engine/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix bug in monitor_module.cc Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/voice_engine/channel_manager.h ('k') | webrtc/voice_engine/dtmf_inband.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 30 matching lines...) Expand all
41 41
42 return *this; 42 return *this;
43 } 43 }
44 44
45 ChannelOwner::ChannelRef::ChannelRef(class Channel* channel) 45 ChannelOwner::ChannelRef::ChannelRef(class Channel* channel)
46 : channel(channel), ref_count(1) {} 46 : channel(channel), ref_count(1) {}
47 47
48 ChannelManager::ChannelManager(uint32_t instance_id, const Config& config) 48 ChannelManager::ChannelManager(uint32_t instance_id, const Config& config)
49 : instance_id_(instance_id), 49 : instance_id_(instance_id),
50 last_channel_id_(-1), 50 last_channel_id_(-1),
51 lock_(CriticalSectionWrapper::CreateCriticalSection()),
52 config_(config), 51 config_(config),
53 event_log_(RtcEventLog::Create()) {} 52 event_log_(RtcEventLog::Create()) {}
54 53
55 ChannelOwner ChannelManager::CreateChannel() { 54 ChannelOwner ChannelManager::CreateChannel() {
56 return CreateChannelInternal(config_); 55 return CreateChannelInternal(config_);
57 } 56 }
58 57
59 ChannelOwner ChannelManager::CreateChannel(const Config& external_config) { 58 ChannelOwner ChannelManager::CreateChannel(const Config& external_config) {
60 return CreateChannelInternal(external_config); 59 return CreateChannelInternal(external_config);
61 } 60 }
62 61
63 ChannelOwner ChannelManager::CreateChannelInternal(const Config& config) { 62 ChannelOwner ChannelManager::CreateChannelInternal(const Config& config) {
64 Channel* channel; 63 Channel* channel;
65 Channel::CreateChannel(channel, ++last_channel_id_, instance_id_, 64 Channel::CreateChannel(channel, ++last_channel_id_, instance_id_,
66 event_log_.get(), config); 65 event_log_.get(), config);
67 ChannelOwner channel_owner(channel); 66 ChannelOwner channel_owner(channel);
68 67
69 CriticalSectionScoped crit(lock_.get()); 68 rtc::CritScope crit(&lock_);
70 69
71 channels_.push_back(channel_owner); 70 channels_.push_back(channel_owner);
72 71
73 return channel_owner; 72 return channel_owner;
74 } 73 }
75 74
76 ChannelOwner ChannelManager::GetChannel(int32_t channel_id) { 75 ChannelOwner ChannelManager::GetChannel(int32_t channel_id) {
77 CriticalSectionScoped crit(lock_.get()); 76 rtc::CritScope crit(&lock_);
78 77
79 for (size_t i = 0; i < channels_.size(); ++i) { 78 for (size_t i = 0; i < channels_.size(); ++i) {
80 if (channels_[i].channel()->ChannelId() == channel_id) 79 if (channels_[i].channel()->ChannelId() == channel_id)
81 return channels_[i]; 80 return channels_[i];
82 } 81 }
83 return ChannelOwner(NULL); 82 return ChannelOwner(NULL);
84 } 83 }
85 84
86 void ChannelManager::GetAllChannels(std::vector<ChannelOwner>* channels) { 85 void ChannelManager::GetAllChannels(std::vector<ChannelOwner>* channels) {
87 CriticalSectionScoped crit(lock_.get()); 86 rtc::CritScope crit(&lock_);
88 87
89 *channels = channels_; 88 *channels = channels_;
90 } 89 }
91 90
92 void ChannelManager::DestroyChannel(int32_t channel_id) { 91 void ChannelManager::DestroyChannel(int32_t channel_id) {
93 assert(channel_id >= 0); 92 assert(channel_id >= 0);
94 // Holds a reference to a channel, this is used so that we never delete 93 // Holds a reference to a channel, this is used so that we never delete
95 // Channels while holding a lock, but rather when the method returns. 94 // Channels while holding a lock, but rather when the method returns.
96 ChannelOwner reference(NULL); 95 ChannelOwner reference(NULL);
97 { 96 {
98 CriticalSectionScoped crit(lock_.get()); 97 rtc::CritScope crit(&lock_);
99 std::vector<ChannelOwner>::iterator to_delete = channels_.end(); 98 std::vector<ChannelOwner>::iterator to_delete = channels_.end();
100 for (auto it = channels_.begin(); it != channels_.end(); ++it) { 99 for (auto it = channels_.begin(); it != channels_.end(); ++it) {
101 Channel* channel = it->channel(); 100 Channel* channel = it->channel();
102 // For channels associated with the channel to be deleted, disassociate 101 // For channels associated with the channel to be deleted, disassociate
103 // with that channel. 102 // with that channel.
104 channel->DisassociateSendChannel(channel_id); 103 channel->DisassociateSendChannel(channel_id);
105 104
106 if (channel->ChannelId() == channel_id) { 105 if (channel->ChannelId() == channel_id) {
107 to_delete = it; 106 to_delete = it;
108 } 107 }
109 } 108 }
110 if (to_delete != channels_.end()) { 109 if (to_delete != channels_.end()) {
111 reference = *to_delete; 110 reference = *to_delete;
112 channels_.erase(to_delete); 111 channels_.erase(to_delete);
113 } 112 }
114 } 113 }
115 } 114 }
116 115
117 void ChannelManager::DestroyAllChannels() { 116 void ChannelManager::DestroyAllChannels() {
118 // Holds references so that Channels are not destroyed while holding this 117 // Holds references so that Channels are not destroyed while holding this
119 // lock, but rather when the method returns. 118 // lock, but rather when the method returns.
120 std::vector<ChannelOwner> references; 119 std::vector<ChannelOwner> references;
121 { 120 {
122 CriticalSectionScoped crit(lock_.get()); 121 rtc::CritScope crit(&lock_);
123 references = channels_; 122 references = channels_;
124 channels_.clear(); 123 channels_.clear();
125 } 124 }
126 } 125 }
127 126
128 size_t ChannelManager::NumOfChannels() const { 127 size_t ChannelManager::NumOfChannels() const {
129 CriticalSectionScoped crit(lock_.get()); 128 rtc::CritScope crit(&lock_);
130 return channels_.size(); 129 return channels_.size();
131 } 130 }
132 131
133 RtcEventLog* ChannelManager::GetEventLog() const { 132 RtcEventLog* ChannelManager::GetEventLog() const {
134 return event_log_.get(); 133 return event_log_.get();
135 } 134 }
136 135
137 ChannelManager::Iterator::Iterator(ChannelManager* channel_manager) 136 ChannelManager::Iterator::Iterator(ChannelManager* channel_manager)
138 : iterator_pos_(0) { 137 : iterator_pos_(0) {
139 channel_manager->GetAllChannels(&channels_); 138 channel_manager->GetAllChannels(&channels_);
140 } 139 }
141 140
142 Channel* ChannelManager::Iterator::GetChannel() { 141 Channel* ChannelManager::Iterator::GetChannel() {
143 if (iterator_pos_ < channels_.size()) 142 if (iterator_pos_ < channels_.size())
144 return channels_[iterator_pos_].channel(); 143 return channels_[iterator_pos_].channel();
145 return NULL; 144 return NULL;
146 } 145 }
147 146
148 bool ChannelManager::Iterator::IsValid() { 147 bool ChannelManager::Iterator::IsValid() {
149 return iterator_pos_ < channels_.size(); 148 return iterator_pos_ < channels_.size();
150 } 149 }
151 150
152 void ChannelManager::Iterator::Increment() { 151 void ChannelManager::Iterator::Increment() {
153 ++iterator_pos_; 152 ++iterator_pos_;
154 } 153 }
155 154
156 } // namespace voe 155 } // namespace voe
157 } // namespace webrtc 156 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/voice_engine/channel_manager.h ('k') | webrtc/voice_engine/dtmf_inband.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698