DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
ConcurrentBag.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
Common.h
"
4
#include "
System/Object.h
"
5
#include "
System/Array.h
"
6
#include "
System/Collections/Generic/LinkedList.h
"
7
#include "
System/Threading/CriticalSection.h
"
8
#include "
System/Threading/Lock.h
"
9
10
namespace
DotNetDupe
{
11
namespace
System
{
12
namespace
Collections
{
13
namespace
Concurrent
{
14
21
template
<
typename
T>
22
class
ConcurrentBag
:
public
Object
{
23
private
:
24
mutable
Threading::CriticalSection
m_csLock;
25
Generic::LinkedList<T>
m_list;
26
27
public
:
29
ConcurrentBag
() =
default
;
30
32
~ConcurrentBag
()
override
=
default
;
33
36
void
Add
(
const
T& item) {
37
Threading::CriticalSectionLock
lock(m_csLock);
38
m_list.AddFirst(item);
39
}
40
44
bool
TryTake
(T& result) {
45
Threading::CriticalSectionLock
lock(m_csLock);
46
if
(m_list.GetCount() == 0)
return
false
;
47
48
result = m_list.GetFirst()->Value;
49
m_list.RemoveFirst();
50
return
true
;
51
}
52
56
bool
TryPeek
(T& result)
const
{
57
Threading::CriticalSectionLock
lock(m_csLock);
58
if
(m_list.GetCount() == 0)
return
false
;
59
60
result = m_list.GetFirst()->Value;
61
return
true
;
62
}
63
64
void
Clear
() {
65
Threading::CriticalSectionLock
lock(m_csLock);
66
m_list.Clear();
67
}
68
69
int
GetCount
()
const
{
70
Threading::CriticalSectionLock
lock(m_csLock);
71
return
m_list.GetCount();
72
}
73
74
bool
IsEmpty
()
const
{
75
Threading::CriticalSectionLock
lock(m_csLock);
76
return
m_list.GetCount() == 0;
77
}
78
79
Array<T>
ToArray
()
const
{
80
Threading::CriticalSectionLock
lock(m_csLock);
81
return
m_list.ToArray();
82
}
83
};
84
85
}
86
}
87
}
88
}
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::ConcurrentBag::~ConcurrentBag
~ConcurrentBag() override=default
Destructor.
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::IsEmpty
bool IsEmpty() const
Definition
ConcurrentBag.h:74
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::GetCount
int GetCount() const
Definition
ConcurrentBag.h:69
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::TryPeek
bool TryPeek(T &result) const
Attempts to return an object from the ConcurrentBag without removing it.
Definition
ConcurrentBag.h:56
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::Add
void Add(const T &item)
Adds an object to the ConcurrentBag.
Definition
ConcurrentBag.h:36
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::Clear
void Clear()
Definition
ConcurrentBag.h:64
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::TryTake
bool TryTake(T &result)
Attempts to remove and return an object from the ConcurrentBag.
Definition
ConcurrentBag.h:44
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::ConcurrentBag
ConcurrentBag()=default
Initializes a new instance of the ConcurrentBag class that is empty.
DotNetDupe::System::Collections::Concurrent::ConcurrentBag::ToArray
Array< T > ToArray() const
Definition
ConcurrentBag.h:79
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
ConcurrentBag.h
Generated by
1.18.0