Skip to content

Commit

Permalink
Resolve arm9/arm7 tx/rx deadlock by prioritizing rx
Browse files Browse the repository at this point in the history
  • Loading branch information
fincs committed Dec 21, 2023
1 parent e916eca commit f61bbc6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions source/wfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,15 @@ static int _wfcSend(sgIP_Hub_HWInterface* hw, sgIP_memblock* mb)

NetBuf* pPacket;
unsigned headroom = g_envExtraInfo->wlmgr_hdr_headroom_sz;
while (!(pPacket = netbufAlloc(headroom, mb->thislength, NetBufPool_Tx))) {
// Try again after a little while
threadSleep(1000);
if (!(pPacket = netbufAlloc(headroom, mb->thislength, NetBufPool_Tx))) {
// Drop the packet if we cannot allocate a TX netbuf.
// This is done in order to break a deadlock between the ARM9 and ARM7
// where the 9 is waiting for the 7 to release TX mem, but the 7 is
// waiting for the 9 to release RX mem. In other words, we prioritize
// receiving packets to sending packets.
dietPrint("[WFC] Out of netbuf TX mem\n");
sgIP_memblock_free(mb);
return 1;
}

memcpy(netbufGet(pPacket), mb->datastart, mb->thislength);
Expand Down

0 comments on commit f61bbc6

Please sign in to comment.