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: #include "nsIEventTarget.idl" michael@0: michael@0: [ptr] native PRThread(PRThread); michael@0: michael@0: /** michael@0: * This interface provides a high-level abstraction for an operating system michael@0: * thread. michael@0: * michael@0: * Threads have a built-in event queue, and a thread is an event target that michael@0: * can receive nsIRunnable objects (events) to be processed on the thread. michael@0: * michael@0: * See nsIThreadManager for the API used to create and locate threads. michael@0: */ michael@0: [scriptable, uuid(9c889946-a73a-4af3-ae9a-ea64f7d4e3ca)] michael@0: interface nsIThread : nsIEventTarget michael@0: { michael@0: /** michael@0: * @returns michael@0: * The NSPR thread object corresponding to this nsIThread. michael@0: */ michael@0: [noscript] readonly attribute PRThread PRThread; michael@0: michael@0: /** michael@0: * Shutdown the thread. This method prevents further dispatch of events to michael@0: * the thread, and it causes any pending events to run to completion before michael@0: * the thread joins (see PR_JoinThread) with the current thread. During this michael@0: * method call, events for the current thread may be processed. michael@0: * michael@0: * This method MAY NOT be executed from the thread itself. Instead, it is michael@0: * meant to be executed from another thread (usually the thread that created michael@0: * this thread or the main application thread). When this function returns, michael@0: * the thread will be shutdown, and it will no longer be possible to dispatch michael@0: * events to the thread. michael@0: * michael@0: * @throws NS_ERROR_UNEXPECTED michael@0: * Indicates that this method was erroneously called when this thread was michael@0: * the current thread, that this thread was not created with a call to michael@0: * nsIThreadManager::NewThread, or if this method was called more than once michael@0: * on the thread object. michael@0: */ michael@0: void shutdown(); michael@0: michael@0: /** michael@0: * This method may be called to determine if there are any events ready to be michael@0: * processed. It may only be called when this thread is the current thread. michael@0: * michael@0: * Because events may be added to this thread by another thread, a "false" michael@0: * result does not mean that this thread has no pending events. It only michael@0: * means that there were no pending events when this method was called. michael@0: * michael@0: * @returns michael@0: * A boolean value that if "true" indicates that this thread has one or michael@0: * more pending events. michael@0: * michael@0: * @throws NS_ERROR_UNEXPECTED michael@0: * Indicates that this method was erroneously called when this thread was michael@0: * not the current thread. michael@0: */ michael@0: boolean hasPendingEvents(); michael@0: michael@0: /** michael@0: * Process the next event. If there are no pending events, then this method michael@0: * may wait -- depending on the value of the mayWait parameter -- until an michael@0: * event is dispatched to this thread. This method is re-entrant but may michael@0: * only be called if this thread is the current thread. michael@0: * michael@0: * @param mayWait michael@0: * A boolean parameter that if "true" indicates that the method may block michael@0: * the calling thread to wait for a pending event. michael@0: * michael@0: * @returns michael@0: * A boolean value that if "true" indicates that an event was processed. michael@0: * michael@0: * @throws NS_ERROR_UNEXPECTED michael@0: * Indicates that this method was erroneously called when this thread was michael@0: * not the current thread. michael@0: */ michael@0: boolean processNextEvent(in boolean mayWait); michael@0: };