DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
ConcurrentQueue.h
Go to the documentation of this file.
1
3
4
#pragma once
5
6
#include "
Common.h
"
7
#include "
System/Object.h
"
8
#include "
System/Array.h
"
9
#include "
System/Collections/Generic/LinkedList.h
"
10
#include "
System/Threading/CriticalSection.h
"
11
#include "
System/Threading/Lock.h
"
12
13
namespace
DotNetDupe
{
14
namespace
System
{
15
namespace
Collections
{
16
namespace
Concurrent
{
17
24
template
<
typename
T>
25
class
ConcurrentQueue
:
public
Object
{
26
private
:
27
mutable
Threading::CriticalSection
m_csLock;
28
Generic::LinkedList<T>
m_list;
29
30
public
:
32
ConcurrentQueue
() =
default
;
33
36
void
Enqueue
(
const
T& item) {
38
Threading::CriticalSectionLock
lock(m_csLock);
40
m_list.AddLast(item);
41
}
42
46
bool
TryDequeue
(T& result) {
48
Threading::CriticalSectionLock
lock(m_csLock);
49
if
(m_list.GetCount() == 0) {
50
return
false
;
51
}
52
54
result = m_list.GetFirst()->Value;
55
m_list.RemoveFirst();
56
return
true
;
57
}
58
62
bool
TryPeek
(T& result)
const
{
64
Threading::CriticalSectionLock
lock(m_csLock);
65
if
(m_list.GetCount() == 0) {
66
return
false
;
67
}
68
70
result = m_list.GetFirst()->Value;
71
return
true
;
72
}
73
75
void
Clear
() {
77
Threading::CriticalSectionLock
lock(m_csLock);
79
m_list.Clear();
80
}
81
84
int
GetCount
()
const
{
86
Threading::CriticalSectionLock
lock(m_csLock);
88
return
m_list.GetCount();
89
}
90
93
bool
IsEmpty
()
const
{
95
Threading::CriticalSectionLock
lock(m_csLock);
97
return
m_list.GetCount() == 0;
98
}
99
102
Array<T>
ToArray
()
const
{
104
Threading::CriticalSectionLock
lock(m_csLock);
106
return
m_list.ToArray();
107
}
108
};
109
110
}
111
}
112
}
113
}
Array.h
Provides methods for creating, manipulating, searching, and sorting arrays.
Common.h
Defines common cross-platform macros, export decorators, and fundamental types.
CriticalSection.h
Provides a re-entrant mutual exclusion primitive for thread synchronization.
LinkedList.h
Lock.h
Provides an RAII-style scoped lock wrapper around synchronization primitives.
Object.h
Base object class for DotNetDupe mirroring .NET System.Object.
DotNetDupe::System::Array
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition
Array.h:29
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::ToArray
Array< T > ToArray() const
Copies the elements stored in the ConcurrentQueue to a new array.
Definition
ConcurrentQueue.h:102
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::GetCount
int GetCount() const
Gets the number of elements contained in the ConcurrentQueue.
Definition
ConcurrentQueue.h:84
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::ConcurrentQueue
ConcurrentQueue()=default
Initializes a new instance of the ConcurrentQueue class.
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::Enqueue
void Enqueue(const T &item)
Adds an object to the end of the ConcurrentQueue.
Definition
ConcurrentQueue.h:36
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::TryPeek
bool TryPeek(T &result) const
Attempts to return an object from the beginning of the queue without removing it.
Definition
ConcurrentQueue.h:62
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::IsEmpty
bool IsEmpty() const
Gets a value that indicates whether the ConcurrentQueue is empty.
Definition
ConcurrentQueue.h:93
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::TryDequeue
bool TryDequeue(T &result)
Attempts to remove and return the object at the beginning of the queue.
Definition
ConcurrentQueue.h:46
DotNetDupe::System::Collections::Concurrent::ConcurrentQueue::Clear
void Clear()
Removes all objects from the ConcurrentQueue.
Definition
ConcurrentQueue.h:75
DotNetDupe::System::Collections::Generic::LinkedList
Represents a doubly linked list.
Definition
LinkedList.h:42
DotNetDupe::System::Object
Supports all classes in the DotNetDupe class hierarchy.
Definition
Object.h:18
DotNetDupe::System::Threading::CriticalSection
Provides a re-entrant mutual exclusion primitive for thread synchronization.
Definition
CriticalSection.h:19
DotNetDupe::System::Collections::Concurrent
Definition
BlockingCollection.h:16
DotNetDupe::System::Collections
Definition
BlockingCollection.h:15
DotNetDupe::System::Threading::CriticalSectionLock
Lock< CriticalSection > CriticalSectionLock
Convenience alias for Lock<CriticalSection>.
Definition
Lock.h:71
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
Include
System
Collections
Concurrent
ConcurrentQueue.h
Generated by
1.18.0