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: [scriptable, uuid(ef194cab-3f86-4b61-b132-e5e96a79e5d1)] michael@0: interface nsIThreadPoolListener : nsISupports michael@0: { michael@0: /** michael@0: * Called when a new thread is created by the thread pool. The notification michael@0: * happens on the newly-created thread. michael@0: */ michael@0: void onThreadCreated(); michael@0: michael@0: /** michael@0: * Called when a thread is about to be destroyed by the thread pool. The michael@0: * notification happens on the thread that is about to be destroyed. michael@0: */ michael@0: void onThreadShuttingDown(); michael@0: }; michael@0: michael@0: /** michael@0: * An interface to a thread pool. A thread pool creates a limited number of michael@0: * anonymous (unnamed) worker threads. An event dispatched to the thread pool michael@0: * will be run on the next available worker thread. michael@0: */ michael@0: [scriptable, uuid(53675068-cb3a-40e5-a026-1be5a97c9b23)] michael@0: interface nsIThreadPool : nsIEventTarget michael@0: { michael@0: /** michael@0: * Shutdown the thread pool. This method may not be executed from any thread michael@0: * in the thread pool. Instead, it is meant to be executed from another michael@0: * thread (usually the thread that created this thread pool). When this michael@0: * function returns, the thread pool and all of its threads will be shutdown, michael@0: * and it will no longer be possible to dispatch tasks to the thread pool. michael@0: * michael@0: * As a side effect, events on the current thread will be processed. michael@0: */ michael@0: void shutdown(); michael@0: michael@0: /** michael@0: * Get/set the maximum number of threads allowed at one time in this pool. michael@0: */ michael@0: attribute unsigned long threadLimit; michael@0: michael@0: /** michael@0: * Get/set the maximum number of idle threads kept alive. michael@0: */ michael@0: attribute unsigned long idleThreadLimit; michael@0: michael@0: /** michael@0: * Get/set the amount of time in milliseconds before an idle thread is michael@0: * destroyed. michael@0: */ michael@0: attribute unsigned long idleThreadTimeout; michael@0: michael@0: /** michael@0: * Get/set the number of bytes reserved for the stack of all threads in michael@0: * the pool. By default this is nsIThreadManager::DEFAULT_STACK_SIZE. michael@0: */ michael@0: attribute unsigned long threadStackSize; michael@0: michael@0: /** michael@0: * An optional listener that will be notified when a thread is created or michael@0: * destroyed in the course of the thread pool's operation. michael@0: * michael@0: * A listener will only receive notifications about threads created after the michael@0: * listener is set so it is recommended that the consumer set the listener michael@0: * before dispatching the first event. A listener that receives an michael@0: * onThreadCreated() notification is guaranteed to always receive the michael@0: * corresponding onThreadShuttingDown() notification. michael@0: * michael@0: * The thread pool takes ownership of the listener and releases it when the michael@0: * shutdown() method is called. Threads created after the listener is set will michael@0: * also take ownership of the listener so that the listener will be kept alive michael@0: * long enough to receive the guaranteed onThreadShuttingDown() notification. michael@0: */ michael@0: attribute nsIThreadPoolListener listener; michael@0: michael@0: /** michael@0: * Set the label for threads in the pool. All threads will be named michael@0: * " #", where is a serial number. michael@0: */ michael@0: void setName(in ACString aName); michael@0: };