Files
mono/mcs/class/corlib/System.Threading/ThreadPool.cs
T
Gonzalo Paniagua Javier 9d34f4d930 2004-03-15 Gonzalo Paniagua Javier <[email protected]>
* corlib.dll.sources: added StreamAsyncResult and FileStreamAsyncResult.

	* System/Environment.cs: updated corlib version.

	* System.IO/FileStream.cs: added support for asynchronous I/O without
	using the OS native libraries if available.

	* System.IO/FileStreamAsyncResult.cs: IAsyncResult for asynch. I/O.

	* System.IO/MonoIO.cs: added BeginRead/Write, GetSupportsAsync. Open
	has now a new parameter to tell ifthe file will be used for asynch.
	operations.

	* System.IO/Stream.cs: BeginRead/Write do not use delegates. They just
	are actually synchronous.

	* System.IO/StreamAsyncResult.cs: IAsyncResult for Stream.

	* System.Threading/NativeOverlapped.cs: added 2 new internal fields.
	* System.Threading/Overlapped.cs: implemented, but it's not used.

	* System.Threading/ThreadPool.cs: implemented BindHandle.

svn path=/trunk/mcs/; revision=24069
2004-03-15 21:19:16 +00:00

116 lines
3.4 KiB
C#
Executable File

//
// System.Threading.ThreadPool
//
// Author:
// Patrik Torstensson
// Dick Porter ([email protected])
// Maurer Dietmar ([email protected])
//
// (C) Ximian, Inc. http://www.ximian.com
//
using System;
using System.Collections;
using System.Runtime.CompilerServices;
namespace System.Threading {
public sealed class ThreadPool {
private ThreadPool ()
{
/* nothing to do */
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
static extern bool BindHandleInternal (IntPtr osHandle);
public static bool BindHandle (IntPtr osHandle)
{
return BindHandleInternal (osHandle);
}
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void GetAvailableThreads (out int workerThreads, out int completionPortThreads);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void GetMaxThreads (out int workerThreads, out int completionPortThreads);
public static bool QueueUserWorkItem (WaitCallback callback)
{
IAsyncResult ar = callback.BeginInvoke (null, null, null);
if (ar == null)
return false;
return true;
}
public static bool QueueUserWorkItem (WaitCallback callback, object state)
{
IAsyncResult ar = callback.BeginInvoke (state, null, null);
if (ar == null)
return false;
return true;
}
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
int millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject (waitObject, callBack, state,
(long) millisecondsTimeOutInterval, executeOnlyOnce);
}
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
long millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
if (millisecondsTimeOutInterval < -1)
throw new ArgumentOutOfRangeException ("timeout", "timeout < -1");
if (millisecondsTimeOutInterval > Int32.MaxValue)
throw new NotSupportedException ("Timeout is too big. Maximum is Int32.MaxValue");
TimeSpan timeout = new TimeSpan (0, 0, 0, 0, (int) millisecondsTimeOutInterval);
RegisteredWaitHandle waiter = new RegisteredWaitHandle (waitObject, callBack, state,
timeout, executeOnlyOnce);
QueueUserWorkItem (new WaitCallback (waiter.Wait), null);
return waiter;
}
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
TimeSpan timeout,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject (waitObject, callBack, state,
(long) timeout.TotalMilliseconds, executeOnlyOnce);
}
[CLSCompliant(false)]
public static RegisteredWaitHandle RegisterWaitForSingleObject (WaitHandle waitObject,
WaitOrTimerCallback callBack,
object state,
uint millisecondsTimeOutInterval,
bool executeOnlyOnce)
{
return RegisterWaitForSingleObject (waitObject, callBack, state,
(long) millisecondsTimeOutInterval, executeOnlyOnce);
}
public static bool UnsafeQueueUserWorkItem (WaitCallback callback, object state)
{
IAsyncResult ar = callback.BeginInvoke (state, null, null);
if (ar == null)
return false;
return true;
}
}
}