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/. */ 5 6 #ifndef _LOADMONITOR_H_ 7 #define _LOADMONITOR_H_ 8 9 #include "mozilla/Mutex.h" 10 #include "mozilla/CondVar.h" 11 #include "mozilla/RefPtr.h" 12 #include "mozilla/Atomics.h" 13 #include "nsCOMPtr.h" 14 #include "nsIThread.h" 15 #include "nsIObserver.h" 16 17 namespace mozilla { 18 class LoadInfoCollectRunner; 19 20 class LoadNotificationCallback 21 { 22 public: 23 virtual void LoadChanged(float aSystemLoad, float aProcessLoad) = 0; 24 }; 25 26 class LoadMonitor final : public nsIObserver 27 { 28 public: 29 NS_DECL_THREADSAFE_ISUPPORTS 30 NS_DECL_NSIOBSERVER 31 32 explicit LoadMonitor(int aLoadUpdateInterval); 33 34 nsresult Init(RefPtr<LoadMonitor> &self); 35 void SetLoadChangeCallback(LoadNotificationCallback* aCallback); 36 void Shutdown(); 37 float GetSystemLoad(); 38 float GetProcessLoad(); 39 40 friend class LoadInfoCollectRunner; 41 42 private: 43 ~LoadMonitor(); 44 45 void SetProcessLoad(float load); 46 void SetSystemLoad(float load); 47 void FireCallbacks(); 48 49 int mLoadUpdateInterval; 50 mozilla::Mutex mLock; 51 mozilla::CondVar mCondVar; 52 bool mShutdownPending; 53 nsCOMPtr<nsIThread> mLoadInfoThread; 54 float mSystemLoad; 55 float mProcessLoad; 56 LoadNotificationCallback* mLoadNotificationCallback; 57 }; 58 59 } //namespace 60 61 #endif /* _LOADMONITOR_H_ */ 62