Skip to content

Commit f11a106

Browse files
committed
Update Stream detailed Ref Counts
1 parent 6393eda commit f11a106

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/core/stream.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ QuicStreamInitialize(
8989
Stream->ReceiveCompleteOperation->API_CALL.Context->Type = QUIC_API_TYPE_STRM_RECV_COMPLETE;
9090
Stream->ReceiveCompleteOperation->API_CALL.Context->STRM_RECV_COMPLETE.Stream = Stream;
9191
#if DEBUG
92-
Stream->RefTypeCount[QUIC_STREAM_REF_APP] = 1;
92+
CxPlatRefInitializeMultiple(Stream->RefTypeBiasCount, QUIC_STREAM_REF_COUNT);
93+
CxPlatRefIncrement(&Stream->RefTypeBiasCount[QUIC_STREAM_REF_APP]);
9394
#endif
9495

9596
if (Stream->Flags.Unidirectional) {
@@ -173,6 +174,7 @@ QuicStreamInitialize(
173174

174175
if (Stream) {
175176
#if DEBUG
177+
CxPlatRefDecrement(&Stream->RefTypeBiasCount[QUIC_STREAM_REF_APP]);
176178
CxPlatDispatchLockAcquire(&Connection->Streams.AllStreamsLock);
177179
CxPlatListEntryRemove(&Stream->AllStreamsLink);
178180
CxPlatDispatchLockRelease(&Connection->Streams.AllStreamsLock);

src/core/stream.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ typedef struct QUIC_STREAM {
220220
CXPLAT_REF_COUNT RefCount;
221221

222222
#if DEBUG
223-
short RefTypeCount[QUIC_STREAM_REF_COUNT];
223+
//
224+
// Detailed ref counts.
225+
// Note: These ref counts are biased by 1, so lowest they go is 1. It is an
226+
// error for them to ever be zero.
227+
//
228+
CXPLAT_REF_COUNT RefTypeBiasCount[QUIC_STREAM_REF_COUNT];
224229
#endif
225230

226231
//
@@ -707,7 +712,7 @@ QuicStreamAddRef(
707712
CXPLAT_DBG_ASSERT(Stream->RefCount > 0);
708713

709714
#if DEBUG
710-
InterlockedIncrement16((volatile short*)&Stream->RefTypeCount[Ref]);
715+
CxPlatRefIncrement(&Stream->RefTypeBiasCount[Ref]);
711716
#else
712717
UNREFERENCED_PARAMETER(Ref);
713718
#endif
@@ -732,17 +737,15 @@ QuicStreamRelease(
732737
CXPLAT_TEL_ASSERT(Stream->RefCount > 0);
733738

734739
#if DEBUG
735-
CXPLAT_TEL_ASSERT(Stream->RefTypeCount[Ref] > 0);
736-
uint16_t result = (uint16_t)InterlockedDecrement16((volatile short*)&Stream->RefTypeCount[Ref]);
737-
CXPLAT_TEL_ASSERT(result != 0xFFFF);
740+
CXPLAT_TEL_ASSERT(!CxPlatRefDecrement(&Stream->RefTypeBiasCount[Ref]));
738741
#else
739742
UNREFERENCED_PARAMETER(Ref);
740743
#endif
741744

742745
if (CxPlatRefDecrement(&Stream->RefCount)) {
743746
#if DEBUG
744747
for (uint32_t i = 0; i < QUIC_STREAM_REF_COUNT; i++) {
745-
CXPLAT_TEL_ASSERT(Stream->RefTypeCount[i] == 0);
748+
CXPLAT_TEL_ASSERT(Stream->RefTypeBiasCount[i] == 1);
746749
}
747750
#endif
748751
QuicStreamFree(Stream);

0 commit comments

Comments
 (0)