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 | e06ca3c | 2012-06-29 13:20:14 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/interface/thread_annotations.h" |
| 15 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | namespace webrtc { |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 17 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | class RWLockWrapper; |
| 19 | |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 20 | class LOCKABLE ViEManagerBase { |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 21 | friend class ViEManagedItemScopedBase; |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 22 | friend class ViEManagerScopedBase; |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 23 | friend class ViEManagerWriteScoped; |
| 24 | public: |
| 25 | ViEManagerBase(); |
| 26 | ~ViEManagerBase(); |
| 27 | |
| 28 | private: |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 29 | // Exclusive lock, used by ViEManagerWriteScoped. |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 30 | void WriteLockManager() EXCLUSIVE_LOCK_FUNCTION(); |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 31 | |
| 32 | // Releases exclusive lock, used by ViEManagerWriteScoped. |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 33 | void ReleaseWriteLockManager() UNLOCK_FUNCTION(); |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 34 | |
| 35 | // Increases lock count, used by ViEManagerScopedBase. |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 36 | void ReadLockManager() const SHARED_LOCK_FUNCTION(); |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 37 | |
| 38 | // Releases the lock count, used by ViEManagerScopedBase. |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 39 | void ReleaseLockManager() const UNLOCK_FUNCTION(); |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 40 | |
| 41 | RWLockWrapper& instance_rwlock_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 44 | class SCOPED_LOCKABLE ViEManagerWriteScoped { |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 45 | public: |
andresp@webrtc.org | 7fb75ec | 2013-12-20 20:20:50 +0000 | [diff] [blame] | 46 | explicit ViEManagerWriteScoped(ViEManagerBase* vie_manager) |
| 47 | EXCLUSIVE_LOCK_FUNCTION(vie_manager); |
| 48 | ~ViEManagerWriteScoped() UNLOCK_FUNCTION(); |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 49 | |
| 50 | private: |
| 51 | ViEManagerBase* vie_manager_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 54 | class 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 67 | class ViEManagedItemScopedBase { |
| 68 | public: |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 69 | explicit ViEManagedItemScopedBase(ViEManagerScopedBase* vie_scoped_manager); |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 70 | ~ViEManagedItemScopedBase(); |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 71 | |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 72 | protected: |
mflodman@webrtc.org | cee447a | 2012-06-28 07:29:46 +0000 | [diff] [blame] | 73 | ViEManagerScopedBase* vie_scoped_manager_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 74 | }; |
mflodman@webrtc.org | 9a8fa4e | 2011-12-14 08:18:42 +0000 | [diff] [blame] | 75 | |
| 76 | } // namespace webrtc |
| 77 | |
mflodman@webrtc.org | e06ca3c | 2012-06-29 13:20:14 +0000 | [diff] [blame] | 78 | #endif // WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_ |