Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Add this transmitter to the pending data list, if it isn't already in it.
- static void vAddToPendingList(TTRANSMITTER *pTX)
- {
- // Make sure we aren't already in the list... relying on a flag, urgh.
- if (!pTX->bPendingData)
- {
- // We're going on the end, so we don't point at anyone after us
- pTX->pNextPending=NULL;
- // Add us to the end of the list, if we have a pointer to the end
- if (pLastPending != NULL)
- {
- pLastPending->pNextPending = pTX;
- }
- // Regardless, this one is now the end.
- pLastPending = pTX;
- // Add us to the start of the list, if we don't have one
- if (pFirstPending == NULL)
- {
- pFirstPending = pTX;
- // If there wasn't a list the existing count must be zero, we'll inc it later.
- u32PendingTxCount = 0;
- }
- // Set the flag
- pTX->bPendingData = true;
- // And increment the pending count
- u32PendingTxCount++;
- }
- }
- // Remove a transmitter from the pending list. Hopefully it's at the front.
- static void vRemoveFromPendingList(TTRANSMITTER *pTX)
- {
- TTRANSMITTER *pTXInList;
- // Avoid duff pointers
- if (pTX == NULL)
- return;
- // Make sure it's actually in the list...
- if (pTX->bPendingData)
- {
- // So, we think we're in the list
- // Decrement the count
- if (u32PendingTxCount>0)
- u32PendingTxCount--;
- // Are we the first in the list?
- if (pFirstPending == pTX)
- {
- // It was the first, so the next becomes first
- pFirstPending = pTX->pNextPending;
- // Was it also the last?
- if (pLastPending == pTX)
- {
- // First and last, so clear the pLast
- pLastPending = NULL;
- // And we know there can't be any
- u32PendingTxCount=0;
- }
- }
- else
- {
- // Bugger, we're not the first in the list. So we need to chase down the list until we find this entry
- pTXInList = pFirstPending;
- // We know this first one cannot be us, we've checked for that.
- while (pTXInList != NULL)
- {
- // Are we the next one in the pending list after this one?
- if (pTXInList->pNextPending == pTX)
- {
- // Yes, so clip us out of the list
- pTXInList->pNextPending = pTX->pNextPending;
- // Now, we need to check if this makes this one the last one in the list and update pLast if it does
- if (pTXInList->pNextPending == NULL)
- pLastPending = pTXInList;
- // We can't appear in the list twice, so we're done...
- break;
- }
- // Look at the next pending transmitter
- pTXInList = pTXInList->pNextPending;
- }
- }
- }
- // Now, clear our list maintainence variables against future checking
- pTX->bPendingData = false;
- pTX->pNextPending = NULL;
- }
Add Comment
Please, Sign In to add comment