LCOV - code coverage report
Current view: top level - xpcom/threads - nsMemoryPressure.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 3 16 18.8 %
Date: 2017-07-14 16:53:18 Functions: 1 3 33.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "nsMemoryPressure.h"
       8             : #include "mozilla/Assertions.h"
       9             : #include "mozilla/Atomics.h"
      10             : 
      11             : #include "nsThreadUtils.h"
      12             : 
      13             : using namespace mozilla;
      14             : 
      15             : static Atomic<int32_t, Relaxed> sMemoryPressurePending;
      16             : static_assert(MemPressure_None == 0,
      17             :               "Bad static initialization with the default constructor.");
      18             : 
      19             : MemoryPressureState
      20        1230 : NS_GetPendingMemoryPressure()
      21             : {
      22        1230 :   int32_t value = sMemoryPressurePending.exchange(MemPressure_None);
      23        1230 :   return MemoryPressureState(value);
      24             : }
      25             : 
      26             : void
      27           0 : NS_DispatchEventualMemoryPressure(MemoryPressureState aState)
      28             : {
      29             :   /*
      30             :    * A new memory pressure event erases an ongoing memory pressure, but an
      31             :    * existing "new" memory pressure event takes precedence over a new "ongoing"
      32             :    * memory pressure event.
      33             :    */
      34           0 :   switch (aState) {
      35             :     case MemPressure_None:
      36           0 :       sMemoryPressurePending = MemPressure_None;
      37           0 :       break;
      38             :     case MemPressure_New:
      39           0 :       sMemoryPressurePending = MemPressure_New;
      40           0 :       break;
      41             :     case MemPressure_Ongoing:
      42             :       sMemoryPressurePending.compareExchange(MemPressure_None,
      43           0 :                                              MemPressure_Ongoing);
      44           0 :       break;
      45             :   }
      46           0 : }
      47             : 
      48             : nsresult
      49           0 : NS_DispatchMemoryPressure(MemoryPressureState aState)
      50             : {
      51           0 :   NS_DispatchEventualMemoryPressure(aState);
      52           0 :   nsCOMPtr<nsIRunnable> event = new Runnable("NS_DispatchEventualMemoryPressure");
      53           0 :   return NS_DispatchToMainThread(event);
      54             : }

Generated by: LCOV version 1.13