Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
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
CAP
Commits
8317b958
Unverified
Commit
8317b958
authored
May 08, 2018
by
Lemon
Committed by
GitHub
May 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add AsyncLock (#44)
parent
fb7fb71a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
5 deletions
+70
-5
GrpcConnectionManager.cs
src/SkyWalking.Core/Remote/GrpcConnectionManager.cs
+1
-4
SkyWalking.Core.csproj
src/SkyWalking.Core/SkyWalking.Core.csproj
+0
-1
AsyncLock.cs
src/SkyWalking.Core/Utils/AsyncLock.cs
+69
-0
No files found.
src/SkyWalking.Core/Remote/GrpcConnectionManager.cs
View file @
8317b958
...
...
@@ -17,14 +17,11 @@
*/
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Runtime.CompilerServices
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Nito.AsyncEx
;
using
SkyWalking.Config
;
using
SkyWalking.Logging
;
using
SkyWalking.Utils
;
namespace
SkyWalking.Remote
{
...
...
src/SkyWalking.Core/SkyWalking.Core.csproj
View file @
8317b958
...
...
@@ -17,7 +17,6 @@
<ProjectReference Include="..\SkyWalking.NetworkProtocol\SkyWalking.NetworkProtocol.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.0.0-pre-05" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.4.1" />
</ItemGroup>
</Project>
\ No newline at end of file
src/SkyWalking.Core/Utils/AsyncLock.cs
0 → 100644
View file @
8317b958
/*
* Licensed to the OpenSkywalking under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
using
System
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
SkyWalking.Utils
{
internal
class
AsyncLock
{
private
readonly
SemaphoreSlim
_semaphore
=
new
SemaphoreSlim
(
1
);
private
readonly
Releaser
_releaser
;
private
readonly
Task
<
Releaser
>
_releaserTask
;
public
AsyncLock
()
{
_releaser
=
new
Releaser
(
this
);
_releaserTask
=
Task
.
FromResult
(
_releaser
);
}
public
Task
<
Releaser
>
LockAsync
(
CancellationToken
cancellationToken
=
default
(
CancellationToken
))
{
var
wait
=
_semaphore
.
WaitAsync
(
cancellationToken
);
return
wait
.
IsCompleted
?
_releaserTask
:
wait
.
ContinueWith
(
(
_
,
state
)
=>
((
AsyncLock
)
state
).
_releaser
,
this
,
CancellationToken
.
None
,
TaskContinuationOptions
.
ExecuteSynchronously
,
TaskScheduler
.
Default
);
}
public
Releaser
Lock
()
{
_semaphore
.
Wait
();
return
_releaser
;
}
public
struct
Releaser
:
IDisposable
{
private
readonly
AsyncLock
_toRelease
;
internal
Releaser
(
AsyncLock
toRelease
)
{
_toRelease
=
toRelease
;
}
public
void
Dispose
()
=>
_toRelease
.
_semaphore
.
Release
();
}
}
}
\ No newline at end of file
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