2008-03-05 09:52:00 -05:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Microsoft Research Singularity
|
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
|
|
|
// File: ServiceThread.cs
|
|
|
|
//
|
|
|
|
// Note:
|
|
|
|
//
|
|
|
|
|
|
|
|
using System.Threading;
|
2008-11-17 18:29:00 -05:00
|
|
|
using System.Runtime.CompilerServices;
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
namespace Microsoft.Singularity
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Class processing asynchronous requeusts
|
|
|
|
/// </summary>
|
|
|
|
///
|
2008-03-05 09:52:00 -05:00
|
|
|
public class ServiceThread
|
|
|
|
{
|
|
|
|
internal static void Initialize()
|
|
|
|
{
|
|
|
|
queue = new ServiceRequestQueue();
|
|
|
|
Thread.CreateThread(Thread.CurrentProcess, new ThreadStart(ServiceLoop)).Start();
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Enqueue a request into the service queue
|
|
|
|
/// </summary>
|
|
|
|
///
|
|
|
|
/// <param name="req">Requeuest to enqueu</param>
|
|
|
|
///
|
|
|
|
[NoHeapAllocation]
|
2008-03-05 09:52:00 -05:00
|
|
|
internal static void Request(ServiceRequest req)
|
|
|
|
{
|
2008-11-17 18:29:00 -05:00
|
|
|
// Dequeue the request
|
2008-03-05 09:52:00 -05:00
|
|
|
queue.Enqueue(req);
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
///
|
|
|
|
/// <summary>
|
|
|
|
/// Service thread loop processing requests
|
|
|
|
/// </summary>
|
|
|
|
///
|
2008-03-05 09:52:00 -05:00
|
|
|
private static void ServiceLoop()
|
|
|
|
{
|
|
|
|
while (true) {
|
2008-11-17 18:29:00 -05:00
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
ServiceRequest req = queue.Dequeue();
|
2008-11-17 18:29:00 -05:00
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
req.Service();
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
|
|
|
|
/// <summary> Service queue </summary>
|
|
|
|
private static ServiceRequestQueue queue;
|
|
|
|
|
2008-03-05 09:52:00 -05:00
|
|
|
}
|
|
|
|
}
|