niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 11 | #include <assert.h> |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
pbos@webrtc.org | f5d4cb1 | 2013-05-17 13:44:48 +0000 | [diff] [blame] | 13 | #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" |
| 14 | #include "webrtc/video_engine/vie_manager_base.h" |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 15 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | namespace webrtc { |
| 17 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 18 | ViEManagerBase::ViEManagerBase() |
| 19 | : instance_rwlock_(*RWLockWrapper::CreateRWLock()) { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | } |
| 21 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 22 | ViEManagerBase::~ViEManagerBase() { |
| 23 | delete &instance_rwlock_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | } |
| 25 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 26 | void ViEManagerBase::ReadLockManager() const { |
| 27 | instance_rwlock_.AcquireLockShared(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | } |
| 29 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 30 | void ViEManagerBase::ReleaseLockManager() const { |
| 31 | instance_rwlock_.ReleaseLockShared(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 32 | } |
| 33 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 34 | void ViEManagerBase::WriteLockManager() { |
| 35 | instance_rwlock_.AcquireLockExclusive(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | } |
| 37 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 38 | void ViEManagerBase::ReleaseWriteLockManager() { |
| 39 | instance_rwlock_.ReleaseLockExclusive(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 40 | } |
| 41 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 42 | ViEManagerScopedBase::ViEManagerScopedBase(const ViEManagerBase& ViEManagerBase) |
| 43 | : vie_manager_(&ViEManagerBase), |
| 44 | ref_count_(0) { |
| 45 | vie_manager_->ReadLockManager(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | } |
| 47 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 48 | ViEManagerScopedBase::~ViEManagerScopedBase() { |
| 49 | assert(ref_count_ == 0); |
| 50 | vie_manager_->ReleaseLockManager(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 51 | } |
| 52 | |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 53 | ViEManagerWriteScoped::ViEManagerWriteScoped(ViEManagerBase* vie_manager) |
| 54 | : vie_manager_(vie_manager) { |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 55 | vie_manager_->WriteLockManager(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 56 | } |
| 57 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 58 | ViEManagerWriteScoped::~ViEManagerWriteScoped() { |
| 59 | vie_manager_->ReleaseWriteLockManager(); |
| 60 | } |
| 61 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | ViEManagedItemScopedBase::ViEManagedItemScopedBase( |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 63 | ViEManagerScopedBase* vie_scoped_manager) |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 64 | : vie_scoped_manager_(vie_scoped_manager) { |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 65 | vie_scoped_manager_->ref_count_++; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 66 | } |
| 67 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 68 | ViEManagedItemScopedBase::~ViEManagedItemScopedBase() { |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 69 | vie_scoped_manager_->ref_count_--; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | } |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 71 | |
| 72 | } // namespace webrtc |