Interface nsIThreadPoolType

An interface to a thread pool. A thread pool creates a limited number of anonymous (unnamed) worker threads. An event dispatched to the thread pool will be run on the next available worker thread.

Hierarchy

Properties

idleThreadLimit: number

Get/set the maximum number of idle threads kept alive.

idleThreadTimeout: number

Get/set the amount of time in milliseconds before an idle thread is destroyed.

idleThreadTimeoutRegressive: boolean

If set to true the idle timeout will be calculated as idleThreadTimeout divideded by the number of idle threads at the moment. This may help save memory allocations but still keep reasonable amount of idle threads. Default is false, use |idleThreadTimeout| for all threads.

listener: nsIThreadPoolListener

An optional listener that will be notified when a thread is created or destroyed in the course of the thread pool's operation.

A listener will only receive notifications about threads created after the listener is set so it is recommended that the consumer set the listener before dispatching the first event. A listener that receives an onThreadCreated() notification is guaranteed to always receive the corresponding onThreadShuttingDown() notification.

The thread pool takes ownership of the listener and releases it when the shutdown() method is called. Threads created after the listener is set will also take ownership of the listener so that the listener will be kept alive long enough to receive the guaranteed onThreadShuttingDown() notification.

threadLimit: number

Get/set the maximum number of threads allowed at one time in this pool.

threadStackSize: number

Get/set the number of bytes reserved for the stack of all threads in the pool. By default this is nsIThreadManager::DEFAULT_STACK_SIZE.

Methods

  • Increases the reference count for this interface. The associated instance will not be deleted unless the reference count is returned to zero.

    Returns

    The resulting reference count.

    Returns number

  • Parameters

    • aIID: object
    • Optional aInstancePtr: object

    Returns any

  • A run time mechanism for interface discovery.

    Returns

    NS_OK if the interface is supported by the associated instance, NS_NOINTERFACE if it is not.

    aInstancePtr must not be null.

    Parameters

    • aIID: object

      [in] A requested interface IID

    • aInstancePtr: object

      [out] A pointer to an interface pointer to receive the result.

    Returns void

  • Decreases the reference count for this interface. Generally, if the reference count returns to zero, the associated instance is deleted.

    Returns

    The resulting reference count.

    Returns number

  • Dispatch an event to this event target, but do not run it before delay milliseconds have passed. This function may be called from any thread.

    Throws

    NS_ERROR_INVALID_ARG Indicates that event is null.

    Throws

    NS_ERROR_UNEXPECTED Indicates that the thread is shutting down and has finished processing events, so this event would never run and has not been dispatched, or that delay is zero.

    Parameters

    • event: alreadyAddRefed_nsIRunnable

      The alreadyAddrefed<> event to dispatch.

    • delay: number

      The delay (in ms) before running the event. If event does not rise to the top of the event queue before the delay has passed, it will be set aside to execute once the delay has passed. Otherwise, it will be executed immediately.

    Returns void

  • Version of Dispatch to expose to JS, which doesn't require an alreadyAddRefed<> (it will be converted to that internally)

    Throws

    NS_ERROR_INVALID_ARG Indicates that event is null.

    Throws

    NS_ERROR_UNEXPECTED Indicates that the thread is shutting down and has finished processing events, so this event would never run and has not been dispatched.

    Parameters

    • event: nsIRunnable

      The (raw) event to dispatch.

    • flags: number

      The flags modifying event dispatch. The flags are described in detail below.

    Returns void

  • Dispatch an event to this event target. This function may be called from any thread, and it may be called re-entrantly.

    Throws

    NS_ERROR_INVALID_ARG Indicates that event is null.

    Throws

    NS_ERROR_UNEXPECTED Indicates that the thread is shutting down and has finished processing events, so this event would never run and has not been dispatched.

    Parameters

    • event: alreadyAddRefed_nsIRunnable

      The alreadyAddRefed<> event to dispatch. NOTE that the event will be leaked if it fails to dispatch.

    • flags: number

      The flags modifying event dispatch. The flags are described in detail below.

    Returns void

  • Register an task to be run on this event target when it begins shutting down. Shutdown tasks may be run in any order, and this function may be called from any thread.

    The event target may or may not continue accepting events during or after the shutdown task. The precise behaviour here depends on the event target.

    Throws

    NS_ERROR_INVALID_ARG Indicates that task is null.

    Throws

    NS_ERROR_NOT_IMPLEMENTED Indicates that this event target doesn't support shutdown tasks.

    Throws

    NS_ERROR_UNEXPECTED Indicates that the thread is already shutting down, and no longer accepting events.

    Parameters

    • task: nsITargetShutdownTask

      The task to be registered to the target thread. NOTE that unlike dispatch, this will not leak the task if it fails.

    Returns void

  • Set the label for threads in the pool. All threads will be named " #", where is a serial number.

    Parameters

    • aName: string

    Returns void

  • Set the entire pool's QoS priority. If the priority has not changed, do nothing. Existing threads will update their QoS priority the next time they become active, and newly created threads will set this QoS priority upon creation.

    Parameters

    • aPriority: nsIThread_QoSPriority

    Returns void

  • Shutdown the thread pool. This method may not be executed from any thread in the thread pool. Instead, it is meant to be executed from another thread (usually the thread that created this thread pool). When this function returns, the thread pool and all of its threads will be shutdown, and it will no longer be possible to dispatch tasks to the thread pool.

    As a side effect, events on the current thread will be processed.

    Returns void

  • Shutdown the thread pool, but only wait for aTimeoutMs. After the timeout expires, any threads that have not shutdown yet are leaked and will not block shutdown.

    This method should only be used at during shutdown to cleanup threads that made blocking calls to code outside our control, and can't be safely terminated. We choose to leak them intentionally to avoid a shutdown hang.

    Parameters

    • aTimeoutMs: number

    Returns void

  • Unregisters an task previously registered with registerShutdownTask. This function may be called from any thread.

    Throws

    NS_ERROR_INVALID_ARG Indicates that task is null.

    Throws

    NS_ERROR_NOT_IMPLEMENTED Indicates that this event target doesn't support shutdown tasks.

    Throws

    NS_ERROR_UNEXPECTED Indicates that the thread is already shutting down, and no longer accepting events, or that the shutdown task cannot be found.

    Parameters

    • task: nsITargetShutdownTask

      The task previously registered with registerShutdownTask

    Returns void

Generated using TypeDoc