Interrupt.h (1588B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef js_Interrupt_h 7 #define js_Interrupt_h 8 9 #include "jstypes.h" 10 11 struct JS_PUBLIC_API JSContext; 12 13 using JSInterruptCallback = bool (*)(JSContext*); 14 15 extern JS_PUBLIC_API bool JS_CheckForInterrupt(JSContext* cx); 16 17 /* 18 * These functions allow setting an interrupt callback that will be called 19 * from the JS thread some time after any thread triggered the callback using 20 * JS_RequestInterruptCallback(cx). 21 * 22 * To schedule the GC and for other activities the engine internally triggers 23 * interrupt callbacks. The embedding should thus not rely on callbacks being 24 * triggered through the external API only. 25 * 26 * Important note: Additional callbacks can occur inside the callback handler 27 * if it re-enters the JS engine. The embedding must ensure that the callback 28 * is disconnected before attempting such re-entry. 29 */ 30 extern JS_PUBLIC_API bool JS_AddInterruptCallback(JSContext* cx, 31 JSInterruptCallback callback); 32 33 extern JS_PUBLIC_API bool JS_DisableInterruptCallback(JSContext* cx); 34 35 extern JS_PUBLIC_API void JS_ResetInterruptCallback(JSContext* cx, bool enable); 36 37 extern JS_PUBLIC_API void JS_RequestInterruptCallback(JSContext* cx); 38 39 extern JS_PUBLIC_API void JS_RequestInterruptCallbackCanWait(JSContext* cx); 40 41 #endif // js_Interrupt_h