1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/threads/nsMemoryPressure.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsMemoryPressure_h__ 1.11 +#define nsMemoryPressure_h__ 1.12 + 1.13 +#include "nscore.h" 1.14 + 1.15 +enum MemoryPressureState { 1.16 + /* 1.17 + * No memory pressure. 1.18 + */ 1.19 + MemPressure_None = 0, 1.20 + 1.21 + /* 1.22 + * New memory pressure deteced. 1.23 + * 1.24 + * On a new memory pressure, we stop everything to start cleaning 1.25 + * aggresively the memory used, in order to free as much memory as 1.26 + * possible. 1.27 + */ 1.28 + MemPressure_New, 1.29 + 1.30 + /* 1.31 + * Repeated memory pressure. 1.32 + * 1.33 + * A repeated memory pressure implies to clean softly recent allocations. 1.34 + * It is supposed to happen after a new memory pressure which already 1.35 + * cleaned aggressivley. So there is no need to damage the reactivity of 1.36 + * Gecko by stopping the world again. 1.37 + * 1.38 + * In case of conflict with an new memory pressue, the new memory pressure 1.39 + * takes precedence over an ongoing memory pressure. The reason being 1.40 + * that if no events are processed between 2 notifications (new followed 1.41 + * by ongoing, or ongoing followed by a new) we want to be as aggresive as 1.42 + * possible on the clean-up of the memory. After all, we are trying to 1.43 + * keep Gecko alive as long as possible. 1.44 + */ 1.45 + MemPressure_Ongoing 1.46 +}; 1.47 + 1.48 +/** 1.49 + * Return and erase the latest state of the memory pressure event set by any of 1.50 + * the corresponding dispatch function. 1.51 + */ 1.52 +MemoryPressureState 1.53 +NS_GetPendingMemoryPressure(); 1.54 + 1.55 +/** 1.56 + * This function causes the main thread to fire a memory pressure event 1.57 + * before processing the next event, but if there are no events pending in 1.58 + * the main thread's event queue, the memory pressure event would not be 1.59 + * dispatched until one is enqueued. It is infallible and does not allocate 1.60 + * any memory. 1.61 + * 1.62 + * You may call this function from any thread. 1.63 + */ 1.64 +void 1.65 +NS_DispatchEventualMemoryPressure(MemoryPressureState state); 1.66 + 1.67 +/** 1.68 + * This function causes the main thread to fire a memory pressure event 1.69 + * before processing the next event. We wake up the main thread by adding a 1.70 + * dummy event to its event loop, so, unlike with 1.71 + * NS_DispatchEventualMemoryPressure, this memory-pressure event is always 1.72 + * fired relatively quickly, even if the event loop is otherwise empty. 1.73 + * 1.74 + * You may call this function from any thread. 1.75 + */ 1.76 +nsresult 1.77 +NS_DispatchMemoryPressure(MemoryPressureState state); 1.78 + 1.79 +#endif // nsMemoryPressure_h__