2001-09-23 Dick Porter <dick@ximian.com>
[mono.git] / mcs / class / corlib / System.Threading / Thread.cs
1 //
2 // System.Threading.Thread.cs
3 //
4 // Author:
5 //   Dick Porter (dick@ximian.com)
6 //
7 // (C) Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System.Runtime.Remoting.Contexts;
11 using System.Security.Principal;
12 using System.Globalization;
13 using System.Runtime.CompilerServices;
14
15 namespace System.Threading
16 {
17         public sealed class Thread
18         {
19                 public static Context CurrentContext {
20                         get {
21                                 // FIXME -
22                                 // System.Runtime.Remoting.Context not
23                                 // yet implemented
24                                 return(null);
25                         }
26                 }
27
28                 public static IPrincipal CurrentPrincipal {
29                         get {
30                                 // FIXME -
31                                 // System.Security.Principal.IPrincipal
32                                 // not yet implemented
33                                 return(null);
34                         }
35                         
36                         set {
37                         }
38                 }
39
40                 // Looks up the object associated with the current thread
41                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
42                 private extern static Thread CurrentThread_internal();
43                 
44                 public static Thread CurrentThread {
45                         get {
46                                 return(CurrentThread_internal());
47                         }
48                 }
49
50                 public static LocalDataStoreSlot AllocateDataSlot() {
51                         // FIXME
52                         return(null);
53                 }
54
55                 public static LocalDataStoreSlot AllocateNamedDataSlot(string name) {
56                         // FIXME
57                         return(null);
58                 }
59
60                 public static void FreeNamedDataSlot(string name) {
61                         // FIXME
62                 }
63
64                 public static object GetData(LocalDataStoreSlot slot) {
65                         // FIXME
66                         return(null);
67                 }
68
69                 public static AppDomain GetDomain() {
70                         // FIXME
71                         return(null);
72                 }
73
74                 public static int GetDomainID() {
75                         // FIXME
76                         return(0);
77                 }
78
79                 public static LocalDataStoreSlot GetNamedDataSlot(string name) {
80                         // FIXME
81                         return(null);
82                 }
83
84                 public static void ResetAbort() {
85                         // FIXME
86                 }
87
88                 public static void SetData(LocalDataStoreSlot slot, object data) {
89                         // FIXME
90                 }
91
92                 // Returns milliseconds remaining (due to interrupted sleep)
93                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
94                 private extern static int Sleep_internal(int ms);
95
96                 // Causes thread to give up its timeslice
97                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
98                 private extern static void Schedule_internal();
99                 
100                 public static void Sleep(int millisecondsTimeout) {
101                         if(millisecondsTimeout<0) {
102                                 throw new ArgumentException("Negative timeout");
103                         }
104                         if(millisecondsTimeout==0) {
105                                 // Schedule another thread
106                                 Schedule_internal();
107                         }
108                         int ms_remaining=Sleep_internal(millisecondsTimeout);
109                         if(ms_remaining>0) {
110                                 throw new ThreadInterruptedException("Thread interrupted while sleeping");
111                         }
112                 }
113
114                 public static void Sleep(TimeSpan timeout) {
115                         // LAMESPEC: says to throw ArgumentException too
116                         if(timeout.Milliseconds < 0 || timeout.Milliseconds > Int32.MaxValue) {
117                                 throw new ArgumentOutOfRangeException("Timeout out of range");
118                         }
119                         if(timeout.Milliseconds==0) {
120                                 // Schedule another thread
121                                 Schedule_internal();
122                         }
123                         int ms_remaining=Sleep_internal(timeout.Milliseconds);
124                         if(ms_remaining>0) {
125                                 throw new ThreadInterruptedException("Thread interrupted while sleeping");
126                         }
127                 }
128
129                 private ThreadStart start_delegate=null;
130                 
131                 public Thread(ThreadStart start) {
132                         if(start==null) {
133                                 throw new ArgumentNullException("Null ThreadStart");
134                         }
135
136                         // Nothing actually happens here, the fun
137                         // begins when Thread.Start() is called.  For
138                         // now, just record what the ThreadStart
139                         // delegate is.
140                         start_delegate=start;
141                 }
142
143                 public ApartmentState ApartmentState {
144                         get {
145                                 // FIXME
146                                 return(ApartmentState.Unknown);
147                         }
148                         
149                         set {
150                         }
151                 }
152
153                 public CultureInfo CurrentCulture {
154                         get {
155                                 // FIXME
156                                 return(null);
157                         }
158                         
159                         set {
160                         }
161                 }
162
163                 public CultureInfo CurrentUICulture {
164                         get {
165                                 // FIXME
166                                 return(null);
167                         }
168                         
169                         set {
170                         }
171                 }
172
173                 public bool IsAlive {
174                         get {
175                                 // FIXME
176                                 return(false);
177                         }
178                 }
179
180                 public bool IsBackground {
181                         get {
182                                 // FIXME
183                                 return(false);
184                         }
185                         
186                         set {
187                         }
188                 }
189
190                 private string thread_name=null;
191                 
192                 public string Name {
193                         get {
194                                 return(thread_name);
195                         }
196                         
197                         set {
198                                 thread_name=value;
199                         }
200                 }
201
202                 public ThreadPriority Priority {
203                         get {
204                                 // FIXME
205                                 return(ThreadPriority.Lowest);
206                         }
207                         
208                         set {
209                         }
210                 }
211
212                 public ThreadState ThreadState {
213                         get {
214                                 // FIXME
215                                 return(ThreadState.Unstarted);
216                         }
217                 }
218
219                 public void Abort() {
220                         // FIXME
221                 }
222
223                 public void Abort(object stateInfo) {
224                         // FIXME
225                 }
226
227                 public void Interrupt() {
228                         // FIXME
229                 }
230
231                 public void Join() {
232                         // FIXME
233                 }
234
235                 public bool Join(int millisecondsTimeout) {
236                         if(millisecondsTimeout<0) {
237                                 throw new ArgumentException("Timeout less than zero");
238                         }
239                         // FIXME
240                         return(false);
241                 }
242
243                 public bool Join(TimeSpan timeout) {
244                         // LAMESPEC: says to throw ArgumentException too
245                         if(timeout.Milliseconds < 0 || timeout.Milliseconds > Int32.MaxValue) {
246                                 throw new ArgumentOutOfRangeException("timeout out of range");
247                         }
248                         // FIXME
249                         return(false);
250                 }
251
252                 public void Resume() {
253                         // FIXME
254                 }
255                 
256                 // stores a pthread_t, which is defined as unsigned long
257                 // on my system.  I _think_ windows uses "unsigned int" for
258                 // its thread handles, so that _should_ work too.
259                 private UInt32 system_thread_handle;
260
261                 // Returns the system thread handle
262                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
263                 private extern UInt32 Start_internal(ThreadStart start);
264                 
265                 public void Start() {
266                         system_thread_handle=Start_internal(start_delegate);
267                         // FIXME
268                 }
269
270                 public void Suspend() {
271                         // FIXME
272                 }
273
274                 ~Thread() {
275                         // FIXME
276                 }
277         }
278 }