XPCOM:nsIThreadManager: Difference between revisions

Jump to navigation Jump to search
Line 150: Line 150:
The main thread where UI events are processed and the socket transport thread will use the observer interface defined by <code>nsIThreadInternal</code>.  The main thread will interact with the "native" event system during calls to <code>ProcessNextEvent</code> and <code>Dispatch</code>.  Likewise, the socket transport thread will similarly need to poll sockets and perform I/O operations.  By observing calls to <code>ProcessNextEvent</code>, observers can wait on a native event queue (or poll on a set of file descriptors) instead of waiting on the thread's internal event queue monitor.  When they observe a call to <code>Dispatch</code>, they can use whatever mechanism is appropriate to unblock the thread that is waiting on the native event queue.
The main thread where UI events are processed and the socket transport thread will use the observer interface defined by <code>nsIThreadInternal</code>.  The main thread will interact with the "native" event system during calls to <code>ProcessNextEvent</code> and <code>Dispatch</code>.  Likewise, the socket transport thread will similarly need to poll sockets and perform I/O operations.  By observing calls to <code>ProcessNextEvent</code>, observers can wait on a native event queue (or poll on a set of file descriptors) instead of waiting on the thread's internal event queue monitor.  When they observe a call to <code>Dispatch</code>, they can use whatever mechanism is appropriate to unblock the thread that is waiting on the native event queue.


== How do synchronous tasks work? ==
== How do synchronous events work? ==


When <code>dispatch(..., DISPATCH_SYNC)</code> is called on a <code>nsIEventTarget</code>, it first checks to see if the current thread is the same as the thread where the event would be run.  If it is, then it just runs the event directly without queuing it up.  However, if not, then it must queue up the event to be run when the dispatch target next processes its events.  To avoid returning to the caller immediately, the method gets the current thread and calls its <code>processNextEvent</code> method in a loop until it receives acknowledgement that the queued event has been run.
When <code>Dispatch(event, DISPATCH_SYNC)</code> is called on a <code>nsIEventTarget</code>, it first checks to see if the current thread is the same as the thread where the event would be run.  If it is, then it just runs the event directly without queuing it up.  However, if not, then it must queue the event to be run when the dispatch target next processes its events.  To avoid returning to the caller immediately, the method gets the current thread and calls its <code>ProcessNextEvent</code> method in a loop until it receives acknowledgement that the queued event has been run.


== Development ==
== Development ==
272

edits

Navigation menu