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 #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H | 11 #ifndef WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H |
12 #define WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H | 12 #define WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H |
13 | 13 |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
| 16 #include "webrtc/base/atomicops.h" |
16 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/base/scoped_ptr.h" | 18 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/call/rtc_event_log.h" | 19 #include "webrtc/call/rtc_event_log.h" |
19 #include "webrtc/system_wrappers/interface/atomic32.h" | |
20 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 20 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
21 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
25 class Config; | 25 class Config; |
26 | 26 |
27 namespace voe { | 27 namespace voe { |
28 | 28 |
29 class Channel; | 29 class Channel; |
(...skipping 18 matching lines...) Expand all Loading... |
48 public: | 48 public: |
49 explicit ChannelOwner(Channel* channel); | 49 explicit ChannelOwner(Channel* channel); |
50 ChannelOwner(const ChannelOwner& channel_owner); | 50 ChannelOwner(const ChannelOwner& channel_owner); |
51 | 51 |
52 ~ChannelOwner(); | 52 ~ChannelOwner(); |
53 | 53 |
54 ChannelOwner& operator=(const ChannelOwner& other); | 54 ChannelOwner& operator=(const ChannelOwner& other); |
55 | 55 |
56 Channel* channel() const { return channel_ref_->channel.get(); } | 56 Channel* channel() const { return channel_ref_->channel.get(); } |
57 bool IsValid() { return channel_ref_->channel.get() != NULL; } | 57 bool IsValid() { return channel_ref_->channel.get() != NULL; } |
58 int use_count() const { return channel_ref_->ref_count.Value(); } | 58 int use_count() const { |
| 59 return rtc::AtomicOps::AcquireLoad(&channel_ref_->ref_count); |
| 60 } |
| 61 |
59 private: | 62 private: |
60 // Shared instance of a Channel. Copying ChannelOwners increase the reference | 63 // Shared instance of a Channel. Copying ChannelOwners increase the reference |
61 // count and destroying ChannelOwners decrease references. Channels are | 64 // count and destroying ChannelOwners decrease references. Channels are |
62 // deleted when no references to them are held. | 65 // deleted when no references to them are held. |
63 struct ChannelRef { | 66 struct ChannelRef { |
64 ChannelRef(Channel* channel); | 67 ChannelRef(Channel* channel); |
65 const rtc::scoped_ptr<Channel> channel; | 68 const rtc::scoped_ptr<Channel> channel; |
66 Atomic32 ref_count; | 69 volatile int ref_count; |
67 }; | 70 }; |
68 | 71 |
69 ChannelRef* channel_ref_; | 72 ChannelRef* channel_ref_; |
70 }; | 73 }; |
71 | 74 |
72 class ChannelManager { | 75 class ChannelManager { |
73 public: | 76 public: |
74 ChannelManager(uint32_t instance_id, const Config& config); | 77 ChannelManager(uint32_t instance_id, const Config& config); |
75 | 78 |
76 // Upon construction of an Iterator it will grab a copy of the channel list of | 79 // Upon construction of an Iterator it will grab a copy of the channel list of |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 117 |
115 // Returns a pointer to the event log object stored within the ChannelManager. | 118 // Returns a pointer to the event log object stored within the ChannelManager. |
116 RtcEventLog* GetEventLog() const; | 119 RtcEventLog* GetEventLog() const; |
117 | 120 |
118 private: | 121 private: |
119 // Create a channel given a configuration, |config|. | 122 // Create a channel given a configuration, |config|. |
120 ChannelOwner CreateChannelInternal(const Config& config); | 123 ChannelOwner CreateChannelInternal(const Config& config); |
121 | 124 |
122 uint32_t instance_id_; | 125 uint32_t instance_id_; |
123 | 126 |
124 Atomic32 last_channel_id_; | 127 volatile int last_channel_id_; |
125 | 128 |
126 rtc::scoped_ptr<CriticalSectionWrapper> lock_; | 129 rtc::scoped_ptr<CriticalSectionWrapper> lock_; |
127 std::vector<ChannelOwner> channels_; | 130 std::vector<ChannelOwner> channels_; |
128 | 131 |
129 const Config& config_; | 132 const Config& config_; |
130 rtc::scoped_ptr<RtcEventLog> event_log_; | 133 rtc::scoped_ptr<RtcEventLog> event_log_; |
131 | 134 |
132 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelManager); | 135 RTC_DISALLOW_COPY_AND_ASSIGN(ChannelManager); |
133 }; | 136 }; |
134 } // namespace voe | 137 } // namespace voe |
135 } // namespace webrtc | 138 } // namespace webrtc |
136 | 139 |
137 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H | 140 #endif // WEBRTC_VOICE_ENGINE_CHANNEL_MANAGER_H |
OLD | NEW |