Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
89781fef
Commit
89781fef
authored
Mar 11, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: ProfileStorage
parent
7384ec02
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
26 deletions
+16
-26
ConcurrentProfileStorageCollection.cs
...StackExchange/Redis/ConcurrentProfileStorageCollection.cs
+16
-26
No files found.
StackExchange.Redis/StackExchange/Redis/ConcurrentProfileStorageCollection.cs
View file @
89781fef
...
@@ -24,11 +24,11 @@ public struct ProfiledCommandEnumerable : IEnumerable<IProfiledCommand>
...
@@ -24,11 +24,11 @@ public struct ProfiledCommandEnumerable : IEnumerable<IProfiledCommand>
/// </summary>
/// </summary>
public
struct
Enumerator
:
IEnumerator
<
IProfiledCommand
>
public
struct
Enumerator
:
IEnumerator
<
IProfiledCommand
>
{
{
ProfileStorage
Head
;
private
ProfileStorage
Head
;
ProfileStorage
CurrentBacker
;
private
ProfileStorage
CurrentBacker
;
bool
IsEmpty
=>
Head
==
null
;
private
bool
IsEmpty
=>
Head
==
null
;
bool
IsUnstartedOrFinished
=>
CurrentBacker
==
null
;
private
bool
IsUnstartedOrFinished
=>
CurrentBacker
==
null
;
internal
Enumerator
(
ProfileStorage
head
)
internal
Enumerator
(
ProfileStorage
head
)
{
{
...
@@ -81,7 +81,7 @@ public void Dispose()
...
@@ -81,7 +81,7 @@ public void Dispose()
}
}
}
}
ProfileStorage
Head
;
private
readonly
ProfileStorage
Head
;
internal
ProfiledCommandEnumerable
(
ProfileStorage
head
)
internal
ProfiledCommandEnumerable
(
ProfileStorage
head
)
{
{
...
@@ -94,20 +94,11 @@ internal ProfiledCommandEnumerable(ProfileStorage head)
...
@@ -94,20 +94,11 @@ internal ProfiledCommandEnumerable(ProfileStorage head)
///
///
/// `foreach` will automatically use this method.
/// `foreach` will automatically use this method.
/// </summary>
/// </summary>
public
Enumerator
GetEnumerator
()
public
Enumerator
GetEnumerator
()
=>
new
Enumerator
(
Head
);
{
return
new
Enumerator
(
Head
);
}
IEnumerator
<
IProfiledCommand
>
IEnumerable
<
IProfiledCommand
>.
GetEnumerator
()
IEnumerator
<
IProfiledCommand
>
IEnumerable
<
IProfiledCommand
>.
GetEnumerator
()
=>
GetEnumerator
();
{
return
GetEnumerator
();
}
System
.
Collections
.
IEnumerator
System
.
Collections
.
IEnumerable
.
GetEnumerator
()
System
.
Collections
.
IEnumerator
System
.
Collections
.
IEnumerable
.
GetEnumerator
()
=>
GetEnumerator
();
{
return
GetEnumerator
();
}
}
}
/// <summary>
/// <summary>
...
@@ -116,7 +107,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
...
@@ -116,7 +107,7 @@ System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
///
///
/// Performs better than ConcurrentBag, which is important since profiling code shouldn't impact timings.
/// Performs better than ConcurrentBag, which is important since profiling code shouldn't impact timings.
/// </summary>
/// </summary>
sealed
class
ConcurrentProfileStorageCollection
internal
sealed
class
ConcurrentProfileStorageCollection
{
{
// internal for test purposes
// internal for test purposes
internal
static
int
AllocationCount
=
0
;
internal
static
int
AllocationCount
=
0
;
...
@@ -124,10 +115,10 @@ sealed class ConcurrentProfileStorageCollection
...
@@ -124,10 +115,10 @@ sealed class ConcurrentProfileStorageCollection
// It is, by definition, impossible for an element to be in 2 intrusive collections
// It is, by definition, impossible for an element to be in 2 intrusive collections
// and we force Enumeration to release any reference to the collection object
// and we force Enumeration to release any reference to the collection object
// so we can **always** pool these.
// so we can **always** pool these.
const
int
PoolSize
=
64
;
private
const
int
PoolSize
=
64
;
static
ConcurrentProfileStorageCollection
[]
Pool
=
new
ConcurrentProfileStorageCollection
[
PoolSize
];
private
static
readonly
ConcurrentProfileStorageCollection
[]
Pool
=
new
ConcurrentProfileStorageCollection
[
PoolSize
];
volatile
ProfileStorage
Head
;
private
volatile
ProfileStorage
Head
;
private
ConcurrentProfileStorageCollection
()
{
}
private
ConcurrentProfileStorageCollection
()
{
}
...
@@ -154,9 +145,10 @@ internal static int CountInPool()
...
@@ -154,9 +145,10 @@ internal static int CountInPool()
///
///
/// The element can only be a member of *one* bag.
/// The element can only be a member of *one* bag.
/// </summary>
/// </summary>
/// <param name="command">The command to add.</param>
public
void
Add
(
ProfileStorage
command
)
public
void
Add
(
ProfileStorage
command
)
{
{
do
while
(
true
)
{
{
var
cur
=
Head
;
var
cur
=
Head
;
command
.
NextElement
=
cur
;
command
.
NextElement
=
cur
;
...
@@ -167,7 +159,7 @@ public void Add(ProfileStorage command)
...
@@ -167,7 +159,7 @@ public void Add(ProfileStorage command)
#pragma warning restore 420
#pragma warning restore 420
if
(
object
.
ReferenceEquals
(
got
,
cur
))
break
;
if
(
object
.
ReferenceEquals
(
got
,
cur
))
break
;
}
while
(
true
);
}
}
}
/// <summary>
/// <summary>
...
@@ -219,9 +211,7 @@ public static ConcurrentProfileStorageCollection GetOrCreate()
...
@@ -219,9 +211,7 @@ public static ConcurrentProfileStorageCollection GetOrCreate()
}
}
Interlocked
.
Increment
(
ref
AllocationCount
);
Interlocked
.
Increment
(
ref
AllocationCount
);
found
=
new
ConcurrentProfileStorageCollection
();
return
new
ConcurrentProfileStorageCollection
();
return
found
;
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment