• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
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 
11 #include <assert.h>
12 
13 #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h"
14 #include "webrtc/video_engine/vie_manager_base.h"
15 
16 namespace webrtc {
17 
ViEManagerBase()18 ViEManagerBase::ViEManagerBase()
19     : instance_rwlock_(*RWLockWrapper::CreateRWLock()) {
20 }
21 
~ViEManagerBase()22 ViEManagerBase::~ViEManagerBase() {
23   delete &instance_rwlock_;
24 }
25 
ReadLockManager() const26 void ViEManagerBase::ReadLockManager() const {
27   instance_rwlock_.AcquireLockShared();
28 }
29 
ReleaseLockManager() const30 void ViEManagerBase::ReleaseLockManager() const {
31   instance_rwlock_.ReleaseLockShared();
32 }
33 
WriteLockManager()34 void ViEManagerBase::WriteLockManager() {
35   instance_rwlock_.AcquireLockExclusive();
36 }
37 
ReleaseWriteLockManager()38 void ViEManagerBase::ReleaseWriteLockManager() {
39   instance_rwlock_.ReleaseLockExclusive();
40 }
41 
ViEManagerScopedBase(const ViEManagerBase & ViEManagerBase)42 ViEManagerScopedBase::ViEManagerScopedBase(const ViEManagerBase& ViEManagerBase)
43     : vie_manager_(&ViEManagerBase),
44       ref_count_(0) {
45   vie_manager_->ReadLockManager();
46 }
47 
~ViEManagerScopedBase()48 ViEManagerScopedBase::~ViEManagerScopedBase() {
49   assert(ref_count_ == 0);
50   vie_manager_->ReleaseLockManager();
51 }
52 
ViEManagerWriteScoped(ViEManagerBase * vie_manager)53 ViEManagerWriteScoped::ViEManagerWriteScoped(ViEManagerBase* vie_manager)
54     : vie_manager_(vie_manager) {
55   vie_manager_->WriteLockManager();
56 }
57 
~ViEManagerWriteScoped()58 ViEManagerWriteScoped::~ViEManagerWriteScoped() {
59   vie_manager_->ReleaseWriteLockManager();
60 }
61 
ViEManagedItemScopedBase(ViEManagerScopedBase * vie_scoped_manager)62 ViEManagedItemScopedBase::ViEManagedItemScopedBase(
63     ViEManagerScopedBase* vie_scoped_manager)
64     : vie_scoped_manager_(vie_scoped_manager) {
65   vie_scoped_manager_->ref_count_++;
66 }
67 
~ViEManagedItemScopedBase()68 ViEManagedItemScopedBase::~ViEManagedItemScopedBase() {
69   vie_scoped_manager_->ref_count_--;
70 }
71 
72 }  // namespace webrtc
73