blob: f9f008f3214d96e4a9b3d8b3a85d380ac5e5f8e2 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
mflodman@webrtc.orgcee447a2012-06-28 07:29:46 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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.orge06ca3c2012-06-29 13:20:14 +000011#ifndef WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_
12#define WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000014#include "webrtc/system_wrappers/interface/thread_annotations.h"
15
niklase@google.com470e71d2011-07-07 08:21:25 +000016namespace webrtc {
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000017
niklase@google.com470e71d2011-07-07 08:21:25 +000018class RWLockWrapper;
19
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000020class LOCKABLE ViEManagerBase {
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000021 friend class ViEManagedItemScopedBase;
mflodman@webrtc.orgcee447a2012-06-28 07:29:46 +000022 friend class ViEManagerScopedBase;
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000023 friend class ViEManagerWriteScoped;
24 public:
25 ViEManagerBase();
26 ~ViEManagerBase();
27
28 private:
mflodman@webrtc.orgcee447a2012-06-28 07:29:46 +000029 // Exclusive lock, used by ViEManagerWriteScoped.
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000030 void WriteLockManager() EXCLUSIVE_LOCK_FUNCTION();
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000031
32 // Releases exclusive lock, used by ViEManagerWriteScoped.
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000033 void ReleaseWriteLockManager() UNLOCK_FUNCTION();
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000034
35 // Increases lock count, used by ViEManagerScopedBase.
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000036 void ReadLockManager() const SHARED_LOCK_FUNCTION();
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000037
38 // Releases the lock count, used by ViEManagerScopedBase.
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000039 void ReleaseLockManager() const UNLOCK_FUNCTION();
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000040
41 RWLockWrapper& instance_rwlock_;
niklase@google.com470e71d2011-07-07 08:21:25 +000042};
43
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000044class SCOPED_LOCKABLE ViEManagerWriteScoped {
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000045 public:
andresp@webrtc.org7fb75ec2013-12-20 20:20:50 +000046 explicit ViEManagerWriteScoped(ViEManagerBase* vie_manager)
47 EXCLUSIVE_LOCK_FUNCTION(vie_manager);
48 ~ViEManagerWriteScoped() UNLOCK_FUNCTION();
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000049
50 private:
51 ViEManagerBase* vie_manager_;
niklase@google.com470e71d2011-07-07 08:21:25 +000052};
53
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000054class ViEManagerScopedBase {
55 friend class ViEManagedItemScopedBase;
56 public:
57 explicit ViEManagerScopedBase(const ViEManagerBase& vie_manager);
58 ~ViEManagerScopedBase();
59
60 protected:
61 const ViEManagerBase* vie_manager_;
62
63 private:
64 int ref_count_;
niklase@google.com470e71d2011-07-07 08:21:25 +000065};
66
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000067class ViEManagedItemScopedBase {
68 public:
mflodman@webrtc.orgcee447a2012-06-28 07:29:46 +000069 explicit ViEManagedItemScopedBase(ViEManagerScopedBase* vie_scoped_manager);
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000070 ~ViEManagedItemScopedBase();
mflodman@webrtc.orgcee447a2012-06-28 07:29:46 +000071
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000072 protected:
mflodman@webrtc.orgcee447a2012-06-28 07:29:46 +000073 ViEManagerScopedBase* vie_scoped_manager_;
niklase@google.com470e71d2011-07-07 08:21:25 +000074};
mflodman@webrtc.org9a8fa4e2011-12-14 08:18:42 +000075
76} // namespace webrtc
77
mflodman@webrtc.orge06ca3c2012-06-29 13:20:14 +000078#endif // WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_