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
bbab86d5
Commit
bbab86d5
authored
Mar 23, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DenyExecSync can be init-only
parent
9a3d93c6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
TaskSource.cs
StackExchange.Redis/StackExchange/Redis/TaskSource.cs
+8
-8
No files found.
StackExchange.Redis/StackExchange/Redis/TaskSource.cs
View file @
bbab86d5
...
@@ -20,7 +20,7 @@ static class TaskSource
...
@@ -20,7 +20,7 @@ static class TaskSource
/// Indicates whether the specified task will not hijack threads when results are set
/// Indicates whether the specified task will not hijack threads when results are set
/// </summary>
/// </summary>
public
static
readonly
Func
<
Task
,
bool
>
IsSyncSafe
;
public
static
readonly
Func
<
Task
,
bool
>
IsSyncSafe
;
static
Action
<
Task
>
d
enyExecSync
;
private
static
readonly
Action
<
Task
>
D
enyExecSync
;
static
TaskSource
()
static
TaskSource
()
{
{
try
try
...
@@ -41,7 +41,7 @@ static TaskSource()
...
@@ -41,7 +41,7 @@ static TaskSource()
il
.
Emit
(
OpCodes
.
Or
);
// [task, combined]
il
.
Emit
(
OpCodes
.
Or
);
// [task, combined]
il
.
Emit
(
OpCodes
.
Stfld
,
stateField
);
// []
il
.
Emit
(
OpCodes
.
Stfld
,
stateField
);
// []
il
.
Emit
(
OpCodes
.
Ret
);
il
.
Emit
(
OpCodes
.
Ret
);
d
enyExecSync
=
(
Action
<
Task
>)
method
.
CreateDelegate
(
typeof
(
Action
<
Task
>));
D
enyExecSync
=
(
Action
<
Task
>)
method
.
CreateDelegate
(
typeof
(
Action
<
Task
>));
method
=
new
DynamicMethod
(
"IsSyncSafe"
,
typeof
(
bool
),
new
[]
{
typeof
(
Task
)
},
typeof
(
Task
),
true
);
method
=
new
DynamicMethod
(
"IsSyncSafe"
,
typeof
(
bool
),
new
[]
{
typeof
(
Task
)
},
typeof
(
Task
),
true
);
il
=
method
.
GetILGenerator
();
il
=
method
.
GetILGenerator
();
...
@@ -56,13 +56,13 @@ static TaskSource()
...
@@ -56,13 +56,13 @@ static TaskSource()
// and test them (check for an exception etc)
// and test them (check for an exception etc)
var
tcs
=
new
TaskCompletionSource
<
int
>();
var
tcs
=
new
TaskCompletionSource
<
int
>();
d
enyExecSync
(
tcs
.
Task
);
D
enyExecSync
(
tcs
.
Task
);
if
(!
IsSyncSafe
(
tcs
.
Task
))
if
(!
IsSyncSafe
(
tcs
.
Task
))
{
{
Debug
.
WriteLine
(
"IsSyncSafe reported false!"
);
Debug
.
WriteLine
(
"IsSyncSafe reported false!"
);
Trace
.
WriteLine
(
"IsSyncSafe reported false!"
);
Trace
.
WriteLine
(
"IsSyncSafe reported false!"
);
// revert to not trusting them
// revert to not trusting them
d
enyExecSync
=
null
;
D
enyExecSync
=
null
;
IsSyncSafe
=
null
;
IsSyncSafe
=
null
;
}
}
}
}
...
@@ -71,12 +71,12 @@ static TaskSource()
...
@@ -71,12 +71,12 @@ static TaskSource()
{
{
Debug
.
WriteLine
(
ex
.
Message
);
Debug
.
WriteLine
(
ex
.
Message
);
Trace
.
WriteLine
(
ex
.
Message
);
Trace
.
WriteLine
(
ex
.
Message
);
d
enyExecSync
=
null
;
D
enyExecSync
=
null
;
IsSyncSafe
=
null
;
IsSyncSafe
=
null
;
}
}
if
(
d
enyExecSync
==
null
)
if
(
D
enyExecSync
==
null
)
d
enyExecSync
=
t
=>
{
};
// no-op if that fails
D
enyExecSync
=
t
=>
{
};
// no-op if that fails
if
(
IsSyncSafe
==
null
)
if
(
IsSyncSafe
==
null
)
IsSyncSafe
=
t
=>
false
;
// assume: not
IsSyncSafe
=
t
=>
false
;
// assume: not
}
}
...
@@ -87,7 +87,7 @@ static TaskSource()
...
@@ -87,7 +87,7 @@ static TaskSource()
public
static
TaskCompletionSource
<
T
>
CreateDenyExecSync
<
T
>(
object
asyncState
)
public
static
TaskCompletionSource
<
T
>
CreateDenyExecSync
<
T
>(
object
asyncState
)
{
{
var
source
=
new
TaskCompletionSource
<
T
>(
asyncState
);
var
source
=
new
TaskCompletionSource
<
T
>(
asyncState
);
d
enyExecSync
(
source
.
Task
);
D
enyExecSync
(
source
.
Task
);
return
source
;
return
source
;
}
}
/// <summary>
/// <summary>
...
...
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