XPCOM:nsIThreadManager: Difference between revisions

m
 
(6 intermediate revisions by the same user not shown)
Line 6: Line 6:
  interface nsIThreadManager : nsISupports {
  interface nsIThreadManager : nsISupports {
   /**
   /**
     * Create a new named thread (a global, user PRThread).  If the name is
     * Create a new thread (a global, user PRThread).  Currently, flags is
     * non-empty, then the name of the thread must be unique.  Specifying an
     * an unused parameter, that must be 0.
    * empty name results in an anonymous thread that cannot be found later on
    * using the getThread method.
     */
     */
   nsIThread newThread(in ACString name);
   nsIThread newThread(in unsigned long flags);
   
  /**
    * Find a named thread.  If no thread exists by the given name, then null
    * is returned.
    */
  nsIThread getThread(in ACString name);
    
    
   /**
   /**
Line 73: Line 65:
  [scriptable, uuid(...)]
  [scriptable, uuid(...)]
  interface nsIThread : nsIEventTarget {
  interface nsIThread : nsIEventTarget {
  /**
    * Returns the name of the thread, which may be empty if this thread is
    * anonymous.
    */
  readonly attribute ACString name;
   
   /**
   /**
     * Returns the PRThread object corresponding to this nsIThread.
     * Returns the PRThread object corresponding to this nsIThread.
     */
     */
   [noscript] PRThread getPRThread();
   [noscript] readonly attribute PRThread PRThread;
    
    
   /**
   /**
Line 100: Line 86:
   /**
   /**
     * Process the next event.  If there are no pending events, then this
     * Process the next event.  If there are no pending events, then this
     * method will wait until an event is dispatched to this thread.  This
     * method may wait -- provided mayWait is true -- until an event is  
    * method is re-entrant but may only be called if this thread is the
    * dispatched to this thread.  This method is re-entrant but may only be
     * current thread.
    * called if this thread is the current thread.
     *
    * @return A boolean value that is "true" if an event was processed.
     */
     */
   boolean processNextEvent(in boolean mayWait);
   boolean processNextEvent(in boolean mayWait);
Line 211: Line 199:
   * Create a new thread.
   * Create a new thread.
   *
   *
   * @param name
   * @param result
   *        The name of the thread (must be unique) or the empty string to
   *        The resulting nsIThread object.
  *        create an anonymous thread.
   * @param event
   * @param event
   *        The initial event to run on this thread.  This can be null.
   *        The initial event to run on this thread.  This can be null.
  * @param result
  *        The resulting nsIThread object.
   */
   */
  NS_METHOD NS_NewThread(const nsACString &name, nsIRunnable *event,
  NS_METHOD NS_NewThread(nsIThread **result, nsIRunnable *event);
                        nsIThread **result);
   
   
  /**
  /**
Line 237: Line 221:
   */
   */
  NS_METHOD NS_GetMainThread(nsIThread **result);
  NS_METHOD NS_GetMainThread(nsIThread **result);
 
/**
  * Get a reference to the thread with the given name.
  *
  * @param name
  *        The name of the requested thread.  Must be non-empty.
  * @param result
  *        The resulting nsIThread object.
  */
NS_METHOD NS_GetThread(const nsACString &name, nsIThread **result);
   
   
  /**
  /**
Line 300: Line 274:
   
   
  already_AddRefed<nsIThread> do_GetMainThread();
  already_AddRefed<nsIThread> do_GetMainThread();
&nbsp;
already_AddRefed<nsIThread> do_GetThread(const nsACString &name);


=== nsRunnable ===
=== nsRunnable ===
Line 320: Line 292:
Dispatching <code>MyEvent</code> is then as simple as:
Dispatching <code>MyEvent</code> is then as simple as:


nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
NS_ENSURE_STATE(thread);
&nbsp;
  nsCOMPtr<nsIRunnable> event = new MyEvent();
  nsCOMPtr<nsIRunnable> event = new MyEvent();
  NS_ENSURE_STATE(event);
  rv = NS_DispatchToCurrentThread(event);
  &nbsp;
  NS_ENSURE_SUCCESS(rv, rv);
thread->Dispatch(event, NS_DISPATCH_NORMAL);


== From JS ==
== From JS ==
272

edits