Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ // 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
- HtmlInputHidden.cs
- TypeDescriptorFilterService.cs
- TreeChangeInfo.cs
- ZipIOCentralDirectoryBlock.cs
- EntityDataSourceViewSchema.cs
- CornerRadiusConverter.cs
- AsyncCallback.cs
- ObjectParameterCollection.cs
- SingleObjectCollection.cs
- PageCache.cs
- SinglePhaseEnlistment.cs
- ExtendedPropertyDescriptor.cs
- SqlFunctions.cs
- DbProviderFactory.cs
- CorrelationTokenInvalidatedHandler.cs
- EmptyStringExpandableObjectConverter.cs
- IxmlLineInfo.cs
- BasicExpressionVisitor.cs
- ButtonChrome.cs
- KeySplineConverter.cs
- WriteTimeStream.cs
- SecurityTokenValidationException.cs
- PasswordTextContainer.cs
- GetImportFileNameRequest.cs
- ErrorInfoXmlDocument.cs
- NetMsmqBindingElement.cs
- XmlMtomReader.cs
- SelectionEditor.cs
- DigestTraceRecordHelper.cs
- TextPointer.cs
- ToolStripItemGlyph.cs
- StylusPointPropertyInfoDefaults.cs
- SignedPkcs7.cs
- DataTemplate.cs
- OrderedParallelQuery.cs
- RefreshPropertiesAttribute.cs
- RegularExpressionValidator.cs
- BufferAllocator.cs
- PrinterUnitConvert.cs
- CanExecuteRoutedEventArgs.cs
- FixedSOMContainer.cs
- CornerRadius.cs
- DiscreteKeyFrames.cs
- PrivilegeNotHeldException.cs
- DockingAttribute.cs
- CacheMemory.cs
- Utils.cs
- DesignTimeTemplateParser.cs
- WindowsSlider.cs
- XmlDownloadManager.cs
- Utils.cs
- UnauthorizedAccessException.cs
- IndexExpression.cs
- CFStream.cs
- UnknownBitmapEncoder.cs
- ErrorFormatter.cs
- _LazyAsyncResult.cs
- FixedFindEngine.cs
- DataRowComparer.cs
- ButtonField.cs
- PrimitiveSchema.cs
- FixedSOMPageConstructor.cs
- TextServicesCompartmentContext.cs
- MobileSysDescriptionAttribute.cs
- rsa.cs
- AppSettingsReader.cs
- GridView.cs
- SqlBuffer.cs
- SamlEvidence.cs
- SplitterPanel.cs
- TrackingProfileCache.cs
- GridView.cs
- UiaCoreApi.cs
- ContextMenu.cs
- TitleStyle.cs
- HttpAsyncResult.cs
- SessionStateUtil.cs
- WebPartDisplayModeCollection.cs
- FixUp.cs
- ButtonRenderer.cs
- DateTimeOffset.cs
- ContainerControl.cs
- DataGridViewCellStateChangedEventArgs.cs
- MdiWindowListItemConverter.cs
- DigestTraceRecordHelper.cs
- GenericTypeParameterBuilder.cs
- DataControlField.cs
- RowsCopiedEventArgs.cs
- StylusPointPropertyUnit.cs
- UnsafeNativeMethods.cs
- InkCanvasInnerCanvas.cs
- CompositeFontFamily.cs
- PowerEase.cs
- DefaultValidator.cs
- DbConnectionFactory.cs
- PersonalizableAttribute.cs
- PenContexts.cs
- EdmTypeAttribute.cs
- LoginCancelEventArgs.cs
- RunWorkerCompletedEventArgs.cs