xpcom/threads/nsIThreadPool.idl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/threads/nsIThreadPool.idl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "nsIEventTarget.idl"
    1.11 +
    1.12 +[scriptable, uuid(ef194cab-3f86-4b61-b132-e5e96a79e5d1)]
    1.13 +interface nsIThreadPoolListener : nsISupports
    1.14 +{
    1.15 +  /**
    1.16 +   * Called when a new thread is created by the thread pool. The notification
    1.17 +   * happens on the newly-created thread.
    1.18 +   */
    1.19 +  void onThreadCreated();
    1.20 +
    1.21 +  /**
    1.22 +   * Called when a thread is about to be destroyed by the thread pool. The
    1.23 +   * notification happens on the thread that is about to be destroyed.
    1.24 +   */
    1.25 +  void onThreadShuttingDown();
    1.26 +};
    1.27 +
    1.28 +/**
    1.29 + * An interface to a thread pool.  A thread pool creates a limited number of
    1.30 + * anonymous (unnamed) worker threads.  An event dispatched to the thread pool
    1.31 + * will be run on the next available worker thread.
    1.32 + */
    1.33 +[scriptable, uuid(53675068-cb3a-40e5-a026-1be5a97c9b23)]
    1.34 +interface nsIThreadPool : nsIEventTarget
    1.35 +{
    1.36 +  /**
    1.37 +   * Shutdown the thread pool.  This method may not be executed from any thread
    1.38 +   * in the thread pool.  Instead, it is meant to be executed from another
    1.39 +   * thread (usually the thread that created this thread pool).  When this
    1.40 +   * function returns, the thread pool and all of its threads will be shutdown,
    1.41 +   * and it will no longer be possible to dispatch tasks to the thread pool.
    1.42 +   *
    1.43 +   * As a side effect, events on the current thread will be processed.
    1.44 +   */
    1.45 +  void shutdown();
    1.46 +
    1.47 +  /**
    1.48 +   * Get/set the maximum number of threads allowed at one time in this pool.
    1.49 +   */
    1.50 +  attribute unsigned long threadLimit;
    1.51 +
    1.52 +  /**
    1.53 +   * Get/set the maximum number of idle threads kept alive.
    1.54 +   */
    1.55 +  attribute unsigned long idleThreadLimit;
    1.56 +
    1.57 +  /**
    1.58 +   * Get/set the amount of time in milliseconds before an idle thread is
    1.59 +   * destroyed.
    1.60 +   */
    1.61 +  attribute unsigned long idleThreadTimeout;
    1.62 +
    1.63 +  /**
    1.64 +   * Get/set the number of bytes reserved for the stack of all threads in
    1.65 +   * the pool. By default this is nsIThreadManager::DEFAULT_STACK_SIZE.
    1.66 +   */
    1.67 +  attribute unsigned long threadStackSize;
    1.68 +
    1.69 +  /**
    1.70 +   * An optional listener that will be notified when a thread is created or
    1.71 +   * destroyed in the course of the thread pool's operation.
    1.72 +   *
    1.73 +   * A listener will only receive notifications about threads created after the
    1.74 +   * listener is set so it is recommended that the consumer set the listener
    1.75 +   * before dispatching the first event. A listener that receives an
    1.76 +   * onThreadCreated() notification is guaranteed to always receive the
    1.77 +   * corresponding onThreadShuttingDown() notification.
    1.78 +   *
    1.79 +   * The thread pool takes ownership of the listener and releases it when the
    1.80 +   * shutdown() method is called. Threads created after the listener is set will
    1.81 +   * also take ownership of the listener so that the listener will be kept alive
    1.82 +   * long enough to receive the guaranteed onThreadShuttingDown() notification.
    1.83 +   */
    1.84 +  attribute nsIThreadPoolListener listener;
    1.85 +
    1.86 +  /**
    1.87 +   * Set the label for threads in the pool. All threads will be named
    1.88 +   * "<aName> #<n>", where <n> is a serial number.
    1.89 +   */
    1.90 +  void setName(in ACString aName);
    1.91 +};

mercurial