Skip to content

Commit

Permalink
netkvm: add comments for CLockFreeDynamicQueue
Browse files Browse the repository at this point in the history
Notes about procedures and synchronization

Signed-off-by: Yuri Benditovich <[email protected]>
  • Loading branch information
ybendito authored and YanVugenfirer committed Dec 31, 2023
1 parent 96d0d03 commit 1af7dfd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions NetKVM/Common/ParaNdis_LockFreeQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ class CLockFreeQueue
};


// NOTE1: Calls to Dequeue() and Peek()
// must be externally synchronized!
// Peek returns object that valid till you're in context
// where Dequeue() can't change the queue state
// IsEmpty() returns only momentary state that can be
// changed at eny time by Dequeue or Enqueue()

// NOTE2: Enqueue() is not synchronized with anything
// and can be used simultaneously from various contexts

template <typename TEntryType>
class CLockFreeDynamicQueue : public CPlacementAllocatable
{
Expand Down Expand Up @@ -238,8 +248,8 @@ class CLockFreeDynamicQueue : public CPlacementAllocatable
}
}

// Single consumer Dequeue, a lock is needed when using this method

// Note: This procedure must be externally synchronized with
// calls to Peek() and Dequeue(), see note NOTE1
TEntryType *Dequeue()
{
TEntryType * ptr = m_Queue.Dequeue();
Expand All @@ -266,6 +276,8 @@ class CLockFreeDynamicQueue : public CPlacementAllocatable
return ptr;
}

// Note: This procedure must be externally synchronized with
// calls to Peek() and Dequeue(), see note NOTE1
TEntryType *Peek()
{
TEntryType * element = m_Queue.Peek();
Expand All @@ -277,6 +289,8 @@ class CLockFreeDynamicQueue : public CPlacementAllocatable
return element;
}

// This procedure is for informational purpose only
// see note NOTE1
BOOLEAN IsEmpty()
{
return m_Queue.IsEmpty() ? (BOOLEAN) m_QueueFullListIsEmpty : FALSE;
Expand Down

0 comments on commit 1af7dfd

Please sign in to comment.