|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "nsIEventTarget.idl" |
|
8 |
|
9 [scriptable, uuid(ef194cab-3f86-4b61-b132-e5e96a79e5d1)] |
|
10 interface nsIThreadPoolListener : nsISupports |
|
11 { |
|
12 /** |
|
13 * Called when a new thread is created by the thread pool. The notification |
|
14 * happens on the newly-created thread. |
|
15 */ |
|
16 void onThreadCreated(); |
|
17 |
|
18 /** |
|
19 * Called when a thread is about to be destroyed by the thread pool. The |
|
20 * notification happens on the thread that is about to be destroyed. |
|
21 */ |
|
22 void onThreadShuttingDown(); |
|
23 }; |
|
24 |
|
25 /** |
|
26 * An interface to a thread pool. A thread pool creates a limited number of |
|
27 * anonymous (unnamed) worker threads. An event dispatched to the thread pool |
|
28 * will be run on the next available worker thread. |
|
29 */ |
|
30 [scriptable, uuid(53675068-cb3a-40e5-a026-1be5a97c9b23)] |
|
31 interface nsIThreadPool : nsIEventTarget |
|
32 { |
|
33 /** |
|
34 * Shutdown the thread pool. This method may not be executed from any thread |
|
35 * in the thread pool. Instead, it is meant to be executed from another |
|
36 * thread (usually the thread that created this thread pool). When this |
|
37 * function returns, the thread pool and all of its threads will be shutdown, |
|
38 * and it will no longer be possible to dispatch tasks to the thread pool. |
|
39 * |
|
40 * As a side effect, events on the current thread will be processed. |
|
41 */ |
|
42 void shutdown(); |
|
43 |
|
44 /** |
|
45 * Get/set the maximum number of threads allowed at one time in this pool. |
|
46 */ |
|
47 attribute unsigned long threadLimit; |
|
48 |
|
49 /** |
|
50 * Get/set the maximum number of idle threads kept alive. |
|
51 */ |
|
52 attribute unsigned long idleThreadLimit; |
|
53 |
|
54 /** |
|
55 * Get/set the amount of time in milliseconds before an idle thread is |
|
56 * destroyed. |
|
57 */ |
|
58 attribute unsigned long idleThreadTimeout; |
|
59 |
|
60 /** |
|
61 * Get/set the number of bytes reserved for the stack of all threads in |
|
62 * the pool. By default this is nsIThreadManager::DEFAULT_STACK_SIZE. |
|
63 */ |
|
64 attribute unsigned long threadStackSize; |
|
65 |
|
66 /** |
|
67 * An optional listener that will be notified when a thread is created or |
|
68 * destroyed in the course of the thread pool's operation. |
|
69 * |
|
70 * A listener will only receive notifications about threads created after the |
|
71 * listener is set so it is recommended that the consumer set the listener |
|
72 * before dispatching the first event. A listener that receives an |
|
73 * onThreadCreated() notification is guaranteed to always receive the |
|
74 * corresponding onThreadShuttingDown() notification. |
|
75 * |
|
76 * The thread pool takes ownership of the listener and releases it when the |
|
77 * shutdown() method is called. Threads created after the listener is set will |
|
78 * also take ownership of the listener so that the listener will be kept alive |
|
79 * long enough to receive the guaranteed onThreadShuttingDown() notification. |
|
80 */ |
|
81 attribute nsIThreadPoolListener listener; |
|
82 |
|
83 /** |
|
84 * Set the label for threads in the pool. All threads will be named |
|
85 * "<aName> #<n>", where <n> is a serial number. |
|
86 */ |
|
87 void setName(in ACString aName); |
|
88 }; |