xpcom/threads/nsMemoryPressure.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
     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/. */
     7 #ifndef nsMemoryPressure_h__
     8 #define nsMemoryPressure_h__
    10 #include "nscore.h"
    12 enum MemoryPressureState {
    13   /*
    14    * No memory pressure.
    15    */
    16   MemPressure_None = 0,
    18   /*
    19    * New memory pressure deteced.
    20    *
    21    * On a new memory pressure, we stop everything to start cleaning
    22    * aggresively the memory used, in order to free as much memory as
    23    * possible.
    24    */
    25   MemPressure_New,
    27   /*
    28    * Repeated memory pressure.
    29    *
    30    * A repeated memory pressure implies to clean softly recent allocations.
    31    * It is supposed to happen after a new memory pressure which already
    32    * cleaned aggressivley.  So there is no need to damage the reactivity of
    33    * Gecko by stopping the world again.
    34    *
    35    * In case of conflict with an new memory pressue, the new memory pressure
    36    * takes precedence over an ongoing memory pressure.  The reason being
    37    * that if no events are processed between 2 notifications (new followed
    38    * by ongoing, or ongoing followed by a new) we want to be as aggresive as
    39    * possible on the clean-up of the memory.  After all, we are trying to
    40    * keep Gecko alive as long as possible.
    41    */
    42   MemPressure_Ongoing
    43 };
    45 /**
    46  * Return and erase the latest state of the memory pressure event set by any of
    47  * the corresponding dispatch function.
    48  */
    49 MemoryPressureState
    50 NS_GetPendingMemoryPressure();
    52 /**
    53  * This function causes the main thread to fire a memory pressure event
    54  * before processing the next event, but if there are no events pending in
    55  * the main thread's event queue, the memory pressure event would not be
    56  * dispatched until one is enqueued. It is infallible and does not allocate
    57  * any memory.
    58  *
    59  * You may call this function from any thread.
    60  */
    61 void
    62 NS_DispatchEventualMemoryPressure(MemoryPressureState state);
    64 /**
    65  * This function causes the main thread to fire a memory pressure event
    66  * before processing the next event. We wake up the main thread by adding a
    67  * dummy event to its event loop, so, unlike with
    68  * NS_DispatchEventualMemoryPressure, this memory-pressure event is always
    69  * fired relatively quickly, even if the event loop is otherwise empty.
    70  *
    71  * You may call this function from any thread.
    72  */
    73 nsresult
    74 NS_DispatchMemoryPressure(MemoryPressureState state);
    76 #endif // nsMemoryPressure_h__

mercurial