Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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__