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
16namespace webrtc {
17
18ViEManagerBase::ViEManagerBase()
19    : instance_rwlock_(*RWLockWrapper::CreateRWLock()) {
20}
21
22ViEManagerBase::~ViEManagerBase() {
23  delete &instance_rwlock_;
24}
25
26void ViEManagerBase::ReadLockManager() const {
27  instance_rwlock_.AcquireLockShared();
28}
29
30void ViEManagerBase::ReleaseLockManager() const {
31  instance_rwlock_.ReleaseLockShared();
32}
33
34void ViEManagerBase::WriteLockManager() {
35  instance_rwlock_.AcquireLockExclusive();
36}
37
38void ViEManagerBase::ReleaseWriteLockManager() {
39  instance_rwlock_.ReleaseLockExclusive();
40}
41
42ViEManagerScopedBase::ViEManagerScopedBase(const ViEManagerBase& ViEManagerBase)
43    : vie_manager_(&ViEManagerBase),
44      ref_count_(0) {
45  vie_manager_->ReadLockManager();
46}
47
48ViEManagerScopedBase::~ViEManagerScopedBase() {
49  assert(ref_count_ == 0);
50  vie_manager_->ReleaseLockManager();
51}
52
53ViEManagerWriteScoped::ViEManagerWriteScoped(ViEManagerBase* vie_manager)
54    : vie_manager_(vie_manager) {
55  vie_manager_->WriteLockManager();
56}
57
58ViEManagerWriteScoped::~ViEManagerWriteScoped() {
59  vie_manager_->ReleaseWriteLockManager();
60}
61
62ViEManagedItemScopedBase::ViEManagedItemScopedBase(
63    ViEManagerScopedBase* vie_scoped_manager)
64    : vie_scoped_manager_(vie_scoped_manager) {
65  vie_scoped_manager_->ref_count_++;
66}
67
68ViEManagedItemScopedBase::~ViEManagedItemScopedBase() {
69  vie_scoped_manager_->ref_count_--;
70}
71
72}  // namespace webrtc
73