michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsMemoryPressure_h__ michael@0: #define nsMemoryPressure_h__ michael@0: michael@0: #include "nscore.h" michael@0: michael@0: enum MemoryPressureState { michael@0: /* michael@0: * No memory pressure. michael@0: */ michael@0: MemPressure_None = 0, michael@0: michael@0: /* michael@0: * New memory pressure deteced. michael@0: * michael@0: * On a new memory pressure, we stop everything to start cleaning michael@0: * aggresively the memory used, in order to free as much memory as michael@0: * possible. michael@0: */ michael@0: MemPressure_New, michael@0: michael@0: /* michael@0: * Repeated memory pressure. michael@0: * michael@0: * A repeated memory pressure implies to clean softly recent allocations. michael@0: * It is supposed to happen after a new memory pressure which already michael@0: * cleaned aggressivley. So there is no need to damage the reactivity of michael@0: * Gecko by stopping the world again. michael@0: * michael@0: * In case of conflict with an new memory pressue, the new memory pressure michael@0: * takes precedence over an ongoing memory pressure. The reason being michael@0: * that if no events are processed between 2 notifications (new followed michael@0: * by ongoing, or ongoing followed by a new) we want to be as aggresive as michael@0: * possible on the clean-up of the memory. After all, we are trying to michael@0: * keep Gecko alive as long as possible. michael@0: */ michael@0: MemPressure_Ongoing michael@0: }; michael@0: michael@0: /** michael@0: * Return and erase the latest state of the memory pressure event set by any of michael@0: * the corresponding dispatch function. michael@0: */ michael@0: MemoryPressureState michael@0: NS_GetPendingMemoryPressure(); michael@0: michael@0: /** michael@0: * This function causes the main thread to fire a memory pressure event michael@0: * before processing the next event, but if there are no events pending in michael@0: * the main thread's event queue, the memory pressure event would not be michael@0: * dispatched until one is enqueued. It is infallible and does not allocate michael@0: * any memory. michael@0: * michael@0: * You may call this function from any thread. michael@0: */ michael@0: void michael@0: NS_DispatchEventualMemoryPressure(MemoryPressureState state); michael@0: michael@0: /** michael@0: * This function causes the main thread to fire a memory pressure event michael@0: * before processing the next event. We wake up the main thread by adding a michael@0: * dummy event to its event loop, so, unlike with michael@0: * NS_DispatchEventualMemoryPressure, this memory-pressure event is always michael@0: * fired relatively quickly, even if the event loop is otherwise empty. michael@0: * michael@0: * You may call this function from any thread. michael@0: */ michael@0: nsresult michael@0: NS_DispatchMemoryPressure(MemoryPressureState state); michael@0: michael@0: #endif // nsMemoryPressure_h__