Home | History | Annotate | Download | only in video_engine
      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 #ifndef WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_
     12 #define WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_
     13 
     14 #include "webrtc/base/thread_annotations.h"
     15 
     16 namespace webrtc {
     17 
     18 class RWLockWrapper;
     19 
     20 class LOCKABLE ViEManagerBase {
     21   friend class ViEManagedItemScopedBase;
     22   friend class ViEManagerScopedBase;
     23   friend class ViEManagerWriteScoped;
     24  public:
     25   ViEManagerBase();
     26   ~ViEManagerBase();
     27 
     28  private:
     29   // Exclusive lock, used by ViEManagerWriteScoped.
     30   void WriteLockManager() EXCLUSIVE_LOCK_FUNCTION();
     31 
     32   // Releases exclusive lock, used by ViEManagerWriteScoped.
     33   void ReleaseWriteLockManager() UNLOCK_FUNCTION();
     34 
     35   // Increases lock count, used by ViEManagerScopedBase.
     36   void ReadLockManager() const SHARED_LOCK_FUNCTION();
     37 
     38   // Releases the lock count, used by ViEManagerScopedBase.
     39   void ReleaseLockManager() const UNLOCK_FUNCTION();
     40 
     41   RWLockWrapper& instance_rwlock_;
     42 };
     43 
     44 class SCOPED_LOCKABLE ViEManagerWriteScoped {
     45  public:
     46   explicit ViEManagerWriteScoped(ViEManagerBase* vie_manager)
     47       EXCLUSIVE_LOCK_FUNCTION(vie_manager);
     48   ~ViEManagerWriteScoped() UNLOCK_FUNCTION();
     49 
     50  private:
     51   ViEManagerBase* vie_manager_;
     52 };
     53 
     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_;
     65 };
     66 
     67 class ViEManagedItemScopedBase {
     68  public:
     69   explicit ViEManagedItemScopedBase(ViEManagerScopedBase* vie_scoped_manager);
     70   ~ViEManagedItemScopedBase();
     71 
     72  protected:
     73   ViEManagerScopedBase* vie_scoped_manager_;
     74 };
     75 
     76 }  // namespace webrtc
     77 
     78 #endif  // WEBRTC_VIDEO_ENGINE_VIE_MANAGER_BASE_H_
     79