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.

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

mercurial