Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Log / System / IO / Log / LogReservationCollection.cs / 1305376 / LogReservationCollection.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.IO.Log
{
using System;
using System.IO.Log;
// NOTE: The reservations in the collection do not account for
// header sizes, out of necessity. The reservations made
// with the record sequence *do* account for header sizes.
//
// In order to maintain sanity, the record sequence only
// deals with reservations that include the header
// size. i.e., if it goes into CLFS, it has the header size
// appended to it.
//
// So that means: If we receive a size from the collection,
// add the header size to it before returning it. If we
// receive a size from our code, subtract the header size
// before giving it to the collection.
//
// Keep this straight, or else.
//
sealed class LogReservationCollection : ReservationCollection
{
LogRecordSequence recordSequence;
internal LogReservationCollection(LogRecordSequence sequence)
{
this.recordSequence = sequence;
}
internal LogRecordSequence RecordSequence
{
get { return this.recordSequence; }
}
internal long GetMatchingReservation(long size)
{
// Reservation coming from CLFS, subtract record header
// size.
//
size -= LogLogRecordHeader.Size;
size = GetBestMatchingReservation(size);
if (size == -1)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ReservationNotFound());
// Reservation coming from the collection, add record
// header size.
//
size += LogLogRecordHeader.Size;
return size;
}
internal void InternalAddReservation(long size)
{
// Reservation coming from CLFS, remove record header
// size.
//
size -= LogLogRecordHeader.Size;
ReservationMade(size);
}
protected override void MakeReservation(long size)
{
if (size < 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("size"));
// Reservation coming from collection, add record header
// size.
//
size += LogLogRecordHeader.Size;
long aligned;
UnsafeNativeMethods.AlignReservedLogSingle(
this.recordSequence.MarshalContext,
size,
out aligned);
UnsafeNativeMethods.AllocReservedLog(
this.recordSequence.MarshalContext,
1,
ref aligned);
}
protected override void FreeReservation(long size)
{
if (size < 0)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ArgumentOutOfRange("size"));
lock(this.recordSequence.LogStore.SyncRoot)
{
SafeMarshalContext context = this.recordSequence.InternalMarshalContext ;
if(context == null || context.IsInvalid)
{
return;
}
// Reservation coming from collection, add record header
// size.
//
size += LogLogRecordHeader.Size;
long aligned;
UnsafeNativeMethods.AlignReservedLogSingle(
context,
size,
out aligned);
// Adjustment must be negative, otherwise it's considered
// a "set". (Yuck.)
//
aligned = -aligned;
UnsafeNativeMethods.FreeReservedLog(
context,
1,
ref aligned);
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RPIdentityRequirement.cs
- ChangeConflicts.cs
- ToolZone.cs
- Repeater.cs
- SpellCheck.cs
- BaseAddressElementCollection.cs
- AssignDesigner.xaml.cs
- EntityEntry.cs
- ManualResetEvent.cs
- HeaderUtility.cs
- XmlDownloadManager.cs
- CheckBox.cs
- Model3D.cs
- recordstatescratchpad.cs
- CryptoApi.cs
- DropShadowBitmapEffect.cs
- XmlSchemaAnnotated.cs
- RijndaelManagedTransform.cs
- EntityModelSchemaGenerator.cs
- ScrollChrome.cs
- FormsAuthenticationTicket.cs
- LoadedEvent.cs
- Config.cs
- ScriptIgnoreAttribute.cs
- CodePageEncoding.cs
- ToolStripContentPanel.cs
- ObjectDisposedException.cs
- FunctionQuery.cs
- UnionCqlBlock.cs
- RequiredAttributeAttribute.cs
- UserControlParser.cs
- EnumValidator.cs
- ToolStripItem.cs
- NativeMethods.cs
- SystemDiagnosticsSection.cs
- WindowsStartMenu.cs
- VectorAnimation.cs
- RadioButtonPopupAdapter.cs
- EncoderParameters.cs
- MyContact.cs
- DiagnosticsConfigurationHandler.cs
- LocatorGroup.cs
- BamlBinaryReader.cs
- MimeParameters.cs
- DataSourceConverter.cs
- Vector3D.cs
- BaseInfoTable.cs
- DropShadowEffect.cs
- diagnosticsswitches.cs
- DecoderNLS.cs
- ValidationEventArgs.cs
- ContractInferenceHelper.cs
- XamlWriter.cs
- Compiler.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- ArgumentsParser.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- CodeSubDirectory.cs
- SettingsBase.cs
- UnsafeNativeMethods.cs
- RemoteWebConfigurationHost.cs
- StrongTypingException.cs
- CompressStream.cs
- TableItemStyle.cs
- ToggleProviderWrapper.cs
- PeerInvitationResponse.cs
- ToolStripSplitStackLayout.cs
- FileBasedResourceGroveler.cs
- PageAsyncTask.cs
- CompositeDataBoundControl.cs
- BidPrivateBase.cs
- Base64Encoding.cs
- DBDataPermission.cs
- TreeView.cs
- DigitalSignatureProvider.cs
- JumpPath.cs
- MaskedTextProvider.cs
- WebPartVerb.cs
- HwndSource.cs
- SqlAliaser.cs
- GridViewCommandEventArgs.cs
- LoginView.cs
- DataSourceHelper.cs
- ListViewSortEventArgs.cs
- ThicknessAnimationUsingKeyFrames.cs
- ColumnBinding.cs
- CurrencyManager.cs
- ExpressionBinding.cs
- AssemblyUtil.cs
- XmlEncApr2001.cs
- SamlAdvice.cs
- UniqueID.cs
- ToolStripControlHost.cs
- QueryExecutionOption.cs
- CaseInsensitiveHashCodeProvider.cs
- ServiceMetadataContractBehavior.cs
- EditorZoneBase.cs
- InstancePersistenceEvent.cs
- AlphabeticalEnumConverter.cs
- CharAnimationBase.cs