Back to index

lightning-sunbird  0.9+nobinonly
nsIThread.idl
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsISupports.idl"
00039 
00040 %{C++
00041 #include "prthread.h"
00042 
00043 #define NS_THREAD_CID                                \
00044 { /* 85CE5510-7808-11d3-A181-0050041CAF44 */         \
00045     0x85ce5510,                                      \
00046     0x7808,                                          \
00047     0x11d3,                                          \
00048     {0xa1, 0x81, 0x00, 0x50, 0x04, 0x1c, 0xaf, 0x44} \
00049 }
00050 
00051 #define NS_THREAD_CONTRACTID "@mozilla.org/thread;1"
00052 #define NS_THREAD_CLASSNAME "Thread"
00053 #if 0
00054 %}
00055 
00056 typedef PRUint32 PRThreadPriority;
00057 typedef PRUint32 PRThreadScope;
00058 typedef PRUint32 PRThreadState;
00059 
00060 %{C++
00061 #endif
00062 %}
00063 
00064 interface nsIRunnable;
00065 
00066 [ptr] native PRThread(PRThread);
00067 
00068 [scriptable, uuid(6be5e380-6886-11d3-9382-00104ba0fd40)]
00069 interface nsIThread : nsISupports
00070 {
00071     // These must all match the values used in prthread.h
00072     const PRUint32 PRIORITY_LOW    = 0;
00073     const PRUint32 PRIORITY_NORMAL = 1;
00074     const PRUint32 PRIORITY_HIGH   = 2;
00075     const PRUint32 PRIORITY_URGENT = 3;
00076 
00077     const PRUint32 SCOPE_LOCAL  = 0;
00078     const PRUint32 SCOPE_GLOBAL = 1;
00079     const PRUint32 SCOPE_BOUND  = 2;
00080 
00081     const PRUint32 STATE_JOINABLE   = 0;
00082     const PRUint32 STATE_UNJOINABLE = 1;
00083 
00084     void join();
00085     void interrupt();
00086 
00087     attribute PRThreadPriority       priority;
00088     readonly attribute PRThreadScope scope;
00089     readonly attribute PRThreadState state;
00090     
00091     [noscript] PRThread GetPRThread();
00092     
00093     void init(in nsIRunnable aRunnable,
00094               in PRUint32 aStackSize,
00095               in PRThreadPriority aPriority,
00096               in PRThreadScope    aScope,
00097               in PRThreadState    aState);
00098 
00099     /*
00100      * Get the currently running thread (really a static method sort of thing).
00101      */
00102     readonly attribute nsIThread currentThread;
00103     
00104     /*
00105      * Sleep to at least this many milliseconds (only works on currrent thread).
00106      */
00107     void sleep(in PRUint32 msec);
00108 
00109 %{C++
00110     // returns the nsIThread for the current thread:
00111     static NS_COM nsresult GetCurrent(nsIThread* *result);
00112 
00113     // returns the nsIThread for an arbitrary PRThread:
00114     static NS_COM nsresult GetIThread(PRThread* prthread, nsIThread* *result);
00115 
00116     // initializes the "main" thread (really, just saves the current thread
00117     // at time of calling. meant to be called once at app startup, in lieu
00118     // of proper static initializers, to save the primordial thread
00119     // for later recall.)
00120     static NS_COM nsresult SetMainThread();
00121 
00122     // return the "main" thread
00123     static NS_COM nsresult GetMainThread(nsIThread **result);
00124 
00125     static NS_COM PRBool IsMainThread(); 
00126 %}
00127 };
00128 
00129 %{C++
00130 extern NS_COM nsresult
00131 NS_NewThread(nsIThread* *result, 
00132              nsIRunnable* runnable,
00133              PRUint32 stackSize = 0,
00134              PRThreadState state = PR_UNJOINABLE_THREAD,
00135              PRThreadPriority priority = PR_PRIORITY_NORMAL,
00136              PRThreadScope scope = PR_GLOBAL_THREAD);
00137 
00138 extern NS_COM nsresult
00139 NS_NewThread(nsIThread* *result, 
00140              PRUint32 stackSize = 0,
00141              PRThreadState state = PR_UNJOINABLE_THREAD,
00142              PRThreadPriority priority = PR_PRIORITY_NORMAL,
00143              PRThreadScope scope = PR_GLOBAL_THREAD);
00144 %}