////////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: ServiceThread.cs
//
// Note:
//
using System.Threading;
using System.Runtime.CompilerServices;
namespace Microsoft.Singularity
{
///
///
/// Class processing asynchronous requeusts
///
///
public class ServiceThread
{
internal static void Initialize()
{
queue = new ServiceRequestQueue();
Thread.CreateThread(Thread.CurrentProcess, new ThreadStart(ServiceLoop)).Start();
}
///
///
/// Enqueue a request into the service queue
///
///
/// Requeuest to enqueu
///
[NoHeapAllocation]
internal static void Request(ServiceRequest req)
{
// Dequeue the request
queue.Enqueue(req);
}
///
///
/// Service thread loop processing requests
///
///
private static void ServiceLoop()
{
while (true) {
ServiceRequest req = queue.Dequeue();
req.Service();
}
}
/// Service queue
private static ServiceRequestQueue queue;
}
}