Bug 1755481: correct documentation of `nsIClipboard::getData`. r=mccr8
[gecko.git] / xpcom / threads / nsIThread.idl
blobd8d3818e2a1d6386605bf3d3059317eec296f4fc
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/. */
7 #include "nsISerialEventTarget.idl"
8 #include "nsIThreadShutdown.idl"
10 %{C++
11 #include "mozilla/AlreadyAddRefed.h"
13 namespace mozilla {
14 class TimeStamp;
15 class TimeDurationValueCalculator;
16 template <typename T> class BaseTimeDuration;
17 typedef BaseTimeDuration<TimeDurationValueCalculator> TimeDuration;
18 enum class EventQueuePriority;
22 [ptr] native PRThread(PRThread);
23 native EventQueuePriority(mozilla::EventQueuePriority);
25 native nsIEventTargetPtr(nsIEventTarget*);
26 native nsISerialEventTargetPtr(nsISerialEventTarget*);
27 native TimeStamp(mozilla::TimeStamp);
28 native TimeDuration(mozilla::TimeDuration);
30 /**
31 * This interface provides a high-level abstraction for an operating system
32 * thread.
34 * Threads have a built-in event queue, and a thread is an event target that
35 * can receive nsIRunnable objects (events) to be processed on the thread.
37 * See nsIThreadManager for the API used to create and locate threads.
39 [builtinclass, scriptable, uuid(5801d193-29d1-4964-a6b7-70eb697ddf2b)]
40 interface nsIThread : nsISerialEventTarget
42 /**
43 * @returns
44 * The NSPR thread object corresponding to this nsIThread.
46 [noscript] readonly attribute PRThread PRThread;
48 /**
49 * @returns
50 * Whether or not this thread may call into JS. Used in the profiler
51 * to avoid some unnecessary locking.
53 [noscript] attribute boolean CanInvokeJS;
56 /**
57 * Shutdown the thread. This method prevents further dispatch of events to
58 * the thread, and it causes any pending events to run to completion before
59 * the thread joins (see PR_JoinThread) with the current thread. During this
60 * method call, events for the current thread may be processed.
62 * This method MAY NOT be executed from the thread itself. Instead, it is
63 * meant to be executed from another thread (usually the thread that created
64 * this thread or the main application thread). When this function returns,
65 * the thread will be shutdown, and it will no longer be possible to dispatch
66 * events to the thread.
68 * @throws NS_ERROR_UNEXPECTED
69 * Indicates that this method was erroneously called when this thread was
70 * the current thread, that this thread was not created with a call to
71 * nsIThreadManager::NewThread, or if this method was called more than once
72 * on the thread object.
74 void shutdown();
76 /**
77 * This method may be called to determine if there are any events ready to be
78 * processed. It may only be called when this thread is the current thread.
80 * Because events may be added to this thread by another thread, a "false"
81 * result does not mean that this thread has no pending events. It only
82 * means that there were no pending events when this method was called.
84 * @returns
85 * A boolean value that if "true" indicates that this thread has one or
86 * more pending events.
88 * @throws NS_ERROR_UNEXPECTED
89 * Indicates that this method was erroneously called when this thread was
90 * not the current thread.
92 boolean hasPendingEvents();
94 /**
95 * Similar to above, but checks only possible high priority queue.
97 boolean hasPendingHighPriorityEvents();
99 /**
100 * Process the next event. If there are no pending events, then this method
101 * may wait -- depending on the value of the mayWait parameter -- until an
102 * event is dispatched to this thread. This method is re-entrant but may
103 * only be called if this thread is the current thread.
105 * @param mayWait
106 * A boolean parameter that if "true" indicates that the method may block
107 * the calling thread to wait for a pending event.
109 * @returns
110 * A boolean value that if "true" indicates that an event was processed.
112 * @throws NS_ERROR_UNEXPECTED
113 * Indicates that this method was erroneously called when this thread was
114 * not the current thread.
116 boolean processNextEvent(in boolean mayWait);
119 * Shutdown the thread asynchronously. This method immediately prevents
120 * further dispatch of events to the thread, and it causes any pending events
121 * to run to completion before this thread joins with the current thread.
123 * UNLIKE shutdown() this does not process events on the current thread.
124 * Instead it merely ensures that the current thread continues running until
125 * this thread has shut down.
127 * This method MAY NOT be executed from the thread itself. Instead, it is
128 * meant to be executed from another thread (usually the thread that created
129 * this thread or the main application thread). When this function returns,
130 * the thread will continue running until it exhausts its event queue.
132 * @throws NS_ERROR_UNEXPECTED
133 * Indicates that this method was erroneously called when this thread was
134 * the current thread, that this thread was not created with a call to
135 * nsIThreadManager::NewNamedThread, or that this method was called more
136 * than once on the thread object.
138 void asyncShutdown();
141 * Like `asyncShutdown`, but also returns a nsIThreadShutdown instance to
142 * allow observing and controlling the thread's async shutdown progress.
144 nsIThreadShutdown beginShutdown();
147 * Dispatch an event to a specified queue for the thread. This function
148 * may be called from any thread, and it may be called re-entrantly.
149 * Most users should use the NS_Dispatch*() functions in nsThreadUtils instead
150 * of calling this directly.
152 * @param event
153 * The alreadyAddRefed<> event to dispatch.
154 * NOTE that the event will be leaked if it fails to dispatch.
155 * @param queue
156 * Which event priority queue this should be added to
158 * @throws NS_ERROR_INVALID_ARG
159 * Indicates that event is null.
160 * @throws NS_ERROR_UNEXPECTED
161 * Indicates that the thread is shutting down and has finished processing
162 * events, so this event would never run and has not been dispatched.
164 [noscript] void dispatchToQueue(in alreadyAddRefed_nsIRunnable event,
165 in EventQueuePriority queue);
168 * Use this attribute to dispatch runnables to the thread. Eventually, the
169 * eventTarget attribute will be the only way to dispatch events to a
170 * thread--nsIThread will no longer inherit from nsIEventTarget.
172 readonly attribute nsIEventTarget eventTarget;
175 * A fast C++ getter for the eventTarget.
177 [noscript,notxpcom] nsIEventTargetPtr EventTarget();
180 * A fast C++ getter for the eventTarget. It asserts that the thread's event
181 * target is an nsISerialEventTarget and then returns it.
183 [noscript,notxpcom] nsISerialEventTargetPtr SerialEventTarget();
186 * This is set to the end of the last 50+ms event that was executed on
187 * this thread (for MainThread only). Otherwise returns a null TimeStamp.
189 [noscript] readonly attribute TimeStamp lastLongTaskEnd;
190 [noscript] readonly attribute TimeStamp lastLongNonIdleTaskEnd;
193 * Get information on the timing of the currently-running event.
195 * @param delay
196 * The amount of time the current running event in the specified queue waited
197 * to run. Will return TimeDuration() if the queue is empty or has not run any
198 * new events since event delay monitoring started. NOTE: delay will be
199 * TimeDuration() if this thread uses a PrioritizedEventQueue (i.e. MainThread)
200 * and the event priority is below Input.
201 * @param start
202 * The time the currently running event began to run, or TimeStamp() if no
203 * event is running.
205 [noscript] void getRunningEventDelay(out TimeDuration delay, out TimeStamp start);
208 * Set information on the timing of the currently-running event.
209 * Overrides the values returned by getRunningEventDelay
211 * @param delay
212 * Delay the running event spent in queues, or TimeDuration() if
213 * there's no running event.
214 * @param start
215 * The time the currently running event began to run, or TimeStamp() if no
216 * event is running.
218 [noscript] void setRunningEventDelay(in TimeDuration delay, in TimeStamp start);
220 [noscript] void setNameForWakeupTelemetry(in ACString name);