DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
ConcurrentStack.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
ConcurrentStack
:
public
Object
{
23
private
:
24
mutable
Threading::CriticalSection
m_csLock;
25
Generic::LinkedList<T>
m_list;
26
27
public
:
29
ConcurrentStack
() =
default
;
30
33
void
Push
(
const
T& item) {
34
Threading::CriticalSectionLock
lock(m_csLock);
35
m_list.AddFirst(item);
36
}
37
41
bool
TryPop
(T& result) {
42
Threading::CriticalSectionLock
lock(m_csLock);
43
if
(m_list.GetCount() == 0) {
44
return
false
;
45
}
46
47
result = m_list.GetFirst()->Value;
48
m_list.RemoveFirst();
49
return
true
;
50
}
51
55
bool
TryPeek
(T& result)
const
{
56
Threading::CriticalSectionLock
lock(m_csLock);
57
if
(m_list.GetCount() == 0) {
58
return
false
;
59
}
60
61
result = m_list.GetFirst()->Value;
62
return
true
;
63
}
64
65
void
Clear
() {
66
Threading::CriticalSectionLock
lock(m_csLock);
67
m_list.Clear();
68
}
69
70
int
GetCount
()
const
{
71
Threading::CriticalSectionLock
lock(m_csLock);
72
return
m_list.GetCount();
73
}
74
75
bool
IsEmpty
()
const
{
76
Threading::CriticalSectionLock
lock(m_csLock);
77
return
m_list.GetCount() == 0;
78
}
79
80
Array<T>
ToArray
()
const
{
81
Threading::CriticalSectionLock
lock(m_csLock);
82
return
m_list.ToArray();
83
}
84
};
85
86
}
87
}
88
}
89
}
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::ConcurrentStack::IsEmpty
bool IsEmpty() const
Definition
ConcurrentStack.h:75
DotNetDupe::System::Collections::Concurrent::ConcurrentStack::GetCount
int GetCount() const
Definition
ConcurrentStack.h:70
DotNetDupe::System::Collections::Concurrent::ConcurrentStack::TryPeek
bool TryPeek(T &result) const
Attempts to return an object from the top of the ConcurrentStack without removing it.
Definition
ConcurrentStack.h:55
DotNetDupe::System::Collections::Concurrent::ConcurrentStack::TryPop
bool TryPop(T &result)
Attempts to pop and return the object at the top of the ConcurrentStack.
Definition
ConcurrentStack.h:41
DotNetDupe::System::Collections::Concurrent::ConcurrentStack::ToArray
Array< T > ToArray() const
Definition
ConcurrentStack.h:80
DotNetDupe::System::Collections::Concurrent::ConcurrentStack::Clear
void Clear()
Definition
ConcurrentStack.h:65
DotNetDupe::System::Collections::Concurrent::ConcurrentStack::ConcurrentStack
ConcurrentStack()=default
Initializes a new instance of the ConcurrentStack class that is empty.
DotNetDupe::System::Collections::Concurrent::ConcurrentStack::Push
void Push(const T &item)
Inserts an object at the top of the ConcurrentStack.
Definition
ConcurrentStack.h:33
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
ConcurrentStack.h
Generated by
1.18.0