singrdk/base/Drivers/Network/Tulip/TulipEventRelay.sg

72 lines
2.2 KiB
Plaintext
Raw Normal View History

2008-03-05 09:52:00 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: TulipEventRelay.sg
//
//
// Note: Right now this interface waits for acks from the receiver.
// This adds an unnecessary context switch. At some future point
// we may be able to have something more akin to a one-way single
// buffer-slot notification system, but for now we ack.
using Microsoft.SingSharp;
using Microsoft.Singularity;
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.Io;
using Microsoft.Singularity.Io.Net;
using Microsoft.Singularity.Directory;
using Microsoft.Singularity.V1.Services;
using System;
using System.Threading;
namespace Microsoft.Singularity.Drivers.Network.Tulip
{
internal struct TulipEvent
{
internal const uint NoEvent = (uint) NicEventType.NoEvent;
internal const uint ReceiveEvent = (uint) NicEventType.ReceiveEvent;
internal const uint TransmitEvent = (uint) NicEventType.TransmitEvent;
internal const uint LinkEvent = (uint) NicEventType.LinkEvent;
}
internal class TulipEventRelay
{
TRef<NicDeviceEventContract.Exp:RUNNING>! channel;
bool channelClosed;
internal TulipEventRelay([Claims]
NicDeviceEventContract.Exp:READY! ep)
{
channel = new TRef<NicDeviceEventContract.Exp:RUNNING>(ep);
channelClosed = false;
}
internal void ForwardEvent(uint tulipEvent)
{
if (channelClosed)
{
return;
}
NicDeviceEventContract.Exp! exp = channel.Acquire();
exp.SendNicDeviceEvent((NicEventType)tulipEvent);
try
{
exp.RecvAckNicDeviceEvent();
}
catch (ChannelClosedException)
{
channelClosed = true;
}
finally
{
channel.Release(exp);
}
}
}
}