Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
c46a7dbb
Unverified
Commit
c46a7dbb
authored
1 year ago
by
s0me0ne-unkn0wn
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Tracking allocator: mark `Spinlock::unlock()` as unsafe and provide a safety contract (#2156)
parent
0c39cf04
Branches
Branches containing commit
No related merge requests found
Pipeline
#409653
passed with stages
in 1 hour, 7 minutes, and 53 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
polkadot/node/tracking-allocator/src/lib.rs
+7
-2
7 additions, 2 deletions
polkadot/node/tracking-allocator/src/lib.rs
with
7 additions
and
2 deletions
polkadot/node/tracking-allocator/src/lib.rs
+
7
−
2
View file @
c46a7dbb
...
...
@@ -72,8 +72,11 @@ impl<T> Spinlock<T> {
}
}
// SAFETY: It should be only called from the guard's destructor. Calling it explicitly while
// the guard is alive is undefined behavior, as it breaks the security contract of `Deref` and
// `DerefMut`, which implies that lock is held at the moment of dereferencing.
#[inline]
fn
unlock
(
&
self
)
{
unsafe
fn
unlock
(
&
self
)
{
self
.lock
.store
(
false
,
Ordering
::
Release
);
}
}
...
...
@@ -97,7 +100,9 @@ impl<T> DerefMut for SpinlockGuard<'_, T> {
impl
<
T
>
Drop
for
SpinlockGuard
<
'_
,
T
>
{
fn
drop
(
&
mut
self
)
{
self
.lock
.unlock
();
// SAFETY: Calling `unlock` is only safe when it's guaranteed no guard outlives the
// unlocking point; here, the guard is dropped, so it is safe.
unsafe
{
self
.lock
.unlock
()
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment