content/media/webrtc/LoadMonitor.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     1 /* -*- Mode: C++; tab-width: 50; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef _LOADMONITOR_H_
     7 #define _LOADMONITOR_H_
     9 #include "mozilla/Mutex.h"
    10 #include "mozilla/CondVar.h"
    11 #include "mozilla/RefPtr.h"
    12 #include "mozilla/Atomics.h"
    13 #include "nsAutoPtr.h"
    14 #include "nsCOMPtr.h"
    15 #include "nsIThread.h"
    16 #include "nsIObserver.h"
    18 namespace mozilla {
    19 class LoadInfoUpdateRunner;
    20 class LoadInfoCollectRunner;
    22 class LoadNotificationCallback
    23 {
    24 public:
    25     virtual void LoadChanged(float aSystemLoad, float aProcessLoad) = 0;
    26 };
    28 class LoadMonitor MOZ_FINAL : public nsIObserver
    29 {
    30 public:
    31     NS_DECL_THREADSAFE_ISUPPORTS
    32     NS_DECL_NSIOBSERVER
    34     LoadMonitor(int aLoadUpdateInterval);
    35     ~LoadMonitor();
    37     nsresult Init(nsRefPtr<LoadMonitor> &self);
    38     void SetLoadChangeCallback(LoadNotificationCallback* aCallback);
    39     void Shutdown();
    40     float GetSystemLoad();
    41     float GetProcessLoad();
    43     friend class LoadInfoCollectRunner;
    45 private:
    47     void SetProcessLoad(float load);
    48     void SetSystemLoad(float load);
    49     void FireCallbacks();
    51     int                  mLoadUpdateInterval;
    52     mozilla::Mutex       mLock;
    53     mozilla::CondVar     mCondVar;
    54     bool                 mShutdownPending;
    55     nsCOMPtr<nsIThread>  mLoadInfoThread;
    56     float                mSystemLoad;
    57     float                mProcessLoad;
    58     LoadNotificationCallback* mLoadNotificationCallback;
    59 };
    61 } //namespace
    63 #endif /* _LOADMONITOR_H_ */

mercurial