XPCOM:nsIThreadManager

From MozillaWiki
Revision as of 16:51, 12 January 2006 by Darin (talk | contribs)
Jump to navigation Jump to search

In a world without nested event queues, the concept of a thread and an event queue merge...

[scriptable, uuid(...)]
interface nsIThreadManager : nsISupports {
  /**
   * Create a new named thread (a global, user PRThread).
   */
  nsIThread newThread(in ACString name);
   
  /**
   * Find a named thread.  The empty string names the current thread.
   * The special value "main" is used to identify the name of the 
   * primordial thread.
   */
  nsIThread getThread(in ACString name);
   
  /**
   * Register an external thread implementation.
   */
  void registerThread(in nsIThread thread);
   
  /**
   * Unregister an external thread implementation.
   */
  void unregisterThread(in nsIThread thread);
   
  /**
   * Shutdown all threads.  This function may only be executed from the
   * primordial thread of the application process.
   */
  void shutdownAll();
};
 
[scriptable, uuid(...)]
interface nsIThread : nsISupports {
  /**
   * Returns the name of the thread.
   */
  readonly attribute ACString name;
   
  /**
   * Shutdown the thread.  This function should not be executed from the
   * thread itself.  Instead, it is meant to be executed from another
   * thread.  When this function returns, the thread will be shutdown, and
   * it will no longer be possible to dispatch tasks to the thread.
   */
  void shutdown();
   
  /**
   * Dispatch a task to the thread.  This function may be executed from any
   * thread.  By default, flags should be 0.  If flags includes DISPATCH_SYNC,
   * then the dispatch function will not return until the task has been run.
   * NOTE: This may have the side-effect of dispatching other tasks to the
   * current thread while waiting for the given task to run.
   */
  void dispatch(in nsIRunnable task, in long flags);
  const long DISPATCH_SYNC = 1;
   
  /**
   * Get the next task assigned to this thread.  This function should block
   * execution of the current thread until a task is available.  NOTE: This
   * may have the side-effect of causing other code to run on the current
   * thread while waiting for a task to become available.  This function may
   * only be called if this thread is the current thread.
   */
  nsIRunnable getNextTask();
   
  /**
   * Returns true if this thread is the current thread.
   */
  boolean isCurrent();
};