File tree Expand file tree Collapse file tree
storage/Tsavorite/cs/src/core/Epochs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44using System ;
55using System . Diagnostics ;
6+ using System . Diagnostics . CodeAnalysis ;
67using System . Runtime . CompilerServices ;
78using System . Runtime . InteropServices ;
89using System . Threading ;
@@ -19,7 +20,7 @@ public sealed unsafe class LightEpoch
1920 /// (1) in AssignInstance, to assign a unique instanceId to each LightEpoch instance, and
2021 /// (2) in Metadata, to track per-thread epoch table entries for each LightEpoch instance.
2122 /// </summary>
22- [ StructLayout ( LayoutKind . Explicit , Size = MaxInstances * sizeof ( int ) ) ]
23+ [ InlineArray ( MaxInstances ) ]
2324 private struct InstanceIndexBuffer
2425 {
2526 /// <summary>
@@ -30,17 +31,17 @@ private struct InstanceIndexBuffer
3031 /// <summary>
3132 /// Anchor field for the buffer.
3233 /// </summary>
33- [ FieldOffset ( 0 ) ]
3434 int field0 ;
3535
3636 /// <summary>
3737 /// Reference to the entry for the given instance ID.
3838 /// </summary>
3939 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
40+ [ UnscopedRef ]
4041 internal ref int GetRef ( int instanceId )
4142 {
4243 Debug . Assert ( instanceId >= 0 && instanceId < MaxInstances ) ;
43- return ref Unsafe . AsRef < int > ( ( int * ) Unsafe . AsPointer ( ref field0 ) + instanceId ) ;
44+ return ref Unsafe . Add ( ref field0 , instanceId ) ;
4445 }
4546 }
4647
Original file line number Diff line number Diff line change 33
44using System ;
55using System . Diagnostics ;
6+ using System . Diagnostics . CodeAnalysis ;
67using System . Runtime . CompilerServices ;
78using System . Runtime . InteropServices ;
89using System . Threading ;
@@ -19,7 +20,7 @@ public sealed unsafe class LightEpoch : IEpochAccessor
1920 /// (1) in AssignInstance, to assign a unique instanceId to each LightEpoch instance, and
2021 /// (2) in Metadata, to track per-thread epoch table entries for each LightEpoch instance.
2122 /// </summary>
22- [ StructLayout ( LayoutKind . Explicit , Size = MaxInstances * sizeof ( int ) ) ]
23+ [ InlineArray ( MaxInstances ) ]
2324 private struct InstanceIndexBuffer
2425 {
2526 /// <summary>
@@ -30,17 +31,17 @@ private struct InstanceIndexBuffer
3031 /// <summary>
3132 /// Anchor field for the buffer.
3233 /// </summary>
33- [ FieldOffset ( 0 ) ]
3434 int field0 ;
3535
3636 /// <summary>
3737 /// Reference to the entry for the given instance ID.
3838 /// </summary>
3939 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
40+ [ UnscopedRef ]
4041 internal ref int GetRef ( int instanceId )
4142 {
4243 Debug . Assert ( instanceId >= 0 && instanceId < MaxInstances ) ;
43- return ref Unsafe . AsRef < int > ( ( int * ) Unsafe . AsPointer ( ref field0 ) + instanceId ) ;
44+ return ref Unsafe . Add ( ref field0 , instanceId ) ;
4445 }
4546 }
4647
You can’t perform that action at this time.
0 commit comments