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
df6523ef
Commit
df6523ef
authored
Mar 25, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Preserve order: didn't (quite); fixed
parent
d80ca807
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
29 deletions
+44
-29
CompletionManager.cs
StackExchange.Redis/StackExchange/Redis/CompletionManager.cs
+44
-29
No files found.
StackExchange.Redis/StackExchange/Redis/CompletionManager.cs
View file @
df6523ef
...
...
@@ -110,43 +110,58 @@ private static void ProcessAsyncCompletionQueue(object state)
}
partial
void
OnCompletedAsync
();
int
activeAsyncWorkerThread
=
0
;
private
void
ProcessAsyncCompletionQueueImpl
()
{
int
total
=
0
;
do
{
ICompletable
next
;
lock
(
asyncCompletionQueue
)
{
next
=
asyncCompletionQueue
.
Count
==
0
?
null
:
asyncCompletionQueue
.
Dequeue
();
}
if
(
next
==
null
&&
Thread
.
Yield
())
// give it a moment and try again
int
currentThread
=
Environment
.
CurrentManagedThreadId
;
try
{
if
(
Interlocked
.
CompareExchange
(
ref
activeAsyncWorkerThread
,
currentThread
,
0
)
!=
0
)
return
;
int
total
=
0
;
do
{
ICompletable
next
;
lock
(
asyncCompletionQueue
)
{
next
=
asyncCompletionQueue
.
Count
==
0
?
null
:
asyncCompletionQueue
.
Dequeue
();
}
}
if
(
next
==
null
)
break
;
// nothing to do
try
{
multiplexer
.
Trace
(
"Completing async (ordered): "
+
next
,
name
);
next
.
TryComplete
(
true
);
Interlocked
.
Increment
(
ref
completedAsync
);
}
catch
(
Exception
ex
)
{
multiplexer
.
Trace
(
"Async completion error: "
+
ex
.
Message
,
name
);
Interlocked
.
Increment
(
ref
failedAsync
);
}
total
++;
}
while
(
true
);
multiplexer
.
Trace
(
"Async completion worker processed "
+
total
+
" operations"
,
name
);
if
(
next
==
null
)
{
// give it a moment and try again, noting that we might lose the battle
// when we pause
Interlocked
.
CompareExchange
(
ref
activeAsyncWorkerThread
,
0
,
currentThread
);
if
(
Thread
.
Yield
()
&&
Interlocked
.
CompareExchange
(
ref
activeAsyncWorkerThread
,
currentThread
,
0
)
==
0
)
{
// we paused, and we got the lock back; anything else?
lock
(
asyncCompletionQueue
)
{
next
=
asyncCompletionQueue
.
Count
==
0
?
null
:
asyncCompletionQueue
.
Dequeue
();
}
}
}
if
(
next
==
null
)
break
;
// nothing to do <===== exit point
try
{
multiplexer
.
Trace
(
"Completing async (ordered): "
+
next
,
name
);
next
.
TryComplete
(
true
);
Interlocked
.
Increment
(
ref
completedAsync
);
}
catch
(
Exception
ex
)
{
multiplexer
.
Trace
(
"Async completion error: "
+
ex
.
Message
,
name
);
Interlocked
.
Increment
(
ref
failedAsync
);
}
total
++;
}
while
(
true
);
multiplexer
.
Trace
(
"Async completion worker processed "
+
total
+
" operations"
,
name
);
}
finally
{
Interlocked
.
CompareExchange
(
ref
activeAsyncWorkerThread
,
0
,
currentThread
);
}
}
}
}
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