Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
redox-os
relibc
Commits
e73b891e
Commit
e73b891e
authored
6 months ago
by
Jeremy Soller
Browse files
Options
Downloads
Plain Diff
Merge branch 'unsafe-blocks-in-sync' into 'master'
use unsafe blocks in `sync/` See merge request
redox-os/relibc!505
parents
d6ef87ad
7df5b16f
No related branches found
Branches containing commit
No related tags found
1 merge request
!505
use unsafe blocks in `sync/`
Pipeline
#16159
passed
6 months ago
Stage: build
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/sync/mod.rs
+5
-2
5 additions, 2 deletions
src/sync/mod.rs
src/sync/mutex.rs
+5
-5
5 additions, 5 deletions
src/sync/mutex.rs
src/sync/waitval.rs
+1
-1
1 addition, 1 deletion
src/sync/waitval.rs
with
11 additions
and
8 deletions
src/sync/mod.rs
+
5
−
2
View file @
e73b891e
// TODO: set this for entire crate when possible
#![deny(unsafe_op_in_unsafe_fn)]
pub
mod
barrier
;
pub
mod
barrier
;
pub
mod
cond
;
pub
mod
cond
;
// TODO: Merge with pthread_mutex
// TODO: Merge with pthread_mutex
...
@@ -95,14 +98,14 @@ impl FutexAtomicTy for AtomicI32 {
...
@@ -95,14 +98,14 @@ impl FutexAtomicTy for AtomicI32 {
pub
unsafe
fn
futex_wake_ptr
(
ptr
:
*
mut
impl
FutexTy
,
n
:
i32
)
->
usize
{
pub
unsafe
fn
futex_wake_ptr
(
ptr
:
*
mut
impl
FutexTy
,
n
:
i32
)
->
usize
{
// TODO: unwrap_unchecked?
// TODO: unwrap_unchecked?
Sys
::
futex_wake
(
ptr
.cast
(),
n
as
u32
)
.unwrap
()
as
usize
unsafe
{
Sys
::
futex_wake
(
ptr
.cast
(),
n
as
u32
)
}
.unwrap
()
as
usize
}
}
pub
unsafe
fn
futex_wait_ptr
<
T
:
FutexTy
>
(
pub
unsafe
fn
futex_wait_ptr
<
T
:
FutexTy
>
(
ptr
:
*
mut
T
,
ptr
:
*
mut
T
,
value
:
T
,
value
:
T
,
deadline_opt
:
Option
<&
timespec
>
,
deadline_opt
:
Option
<&
timespec
>
,
)
->
FutexWaitResult
{
)
->
FutexWaitResult
{
match
Sys
::
futex_wait
(
ptr
.cast
(),
value
.conv
(),
deadline_opt
)
{
match
unsafe
{
Sys
::
futex_wait
(
ptr
.cast
(),
value
.conv
(),
deadline_opt
)
}
{
Ok
(())
=>
FutexWaitResult
::
Waited
,
Ok
(())
=>
FutexWaitResult
::
Waited
,
Err
(
Errno
(
EAGAIN
))
=>
FutexWaitResult
::
Stale
,
Err
(
Errno
(
EAGAIN
))
=>
FutexWaitResult
::
Stale
,
Err
(
Errno
(
ETIMEDOUT
))
if
deadline_opt
.is_some
()
=>
FutexWaitResult
::
TimedOut
,
Err
(
Errno
(
ETIMEDOUT
))
if
deadline_opt
.is_some
()
=>
FutexWaitResult
::
TimedOut
,
...
...
This diff is collapsed.
Click to expand it.
src/sync/mutex.rs
+
5
−
5
View file @
e73b891e
...
@@ -76,8 +76,8 @@ impl<T> Mutex<T> {
...
@@ -76,8 +76,8 @@ impl<T> Mutex<T> {
/// on failure. You should probably not worry about this, it's used for
/// on failure. You should probably not worry about this, it's used for
/// internal optimizations.
/// internal optimizations.
pub
unsafe
fn
manual_try_lock
(
&
self
)
->
Result
<&
mut
T
,
c_int
>
{
pub
unsafe
fn
manual_try_lock
(
&
self
)
->
Result
<&
mut
T
,
c_int
>
{
if
manual_try_lock_generic
(
&
self
.lock
)
{
if
unsafe
{
manual_try_lock_generic
(
&
self
.lock
)
}
{
Ok
(
&
mut
*
self
.content
.get
())
Ok
(
unsafe
{
&
mut
*
self
.content
.get
()
}
)
}
else
{
}
else
{
Err
(
0
)
Err
(
0
)
}
}
...
@@ -86,12 +86,12 @@ impl<T> Mutex<T> {
...
@@ -86,12 +86,12 @@ impl<T> Mutex<T> {
/// your responsibility to unlock it after usage. Mostly useful for FFI:
/// your responsibility to unlock it after usage. Mostly useful for FFI:
/// Prefer normal .lock() where possible.
/// Prefer normal .lock() where possible.
pub
unsafe
fn
manual_lock
(
&
self
)
->
&
mut
T
{
pub
unsafe
fn
manual_lock
(
&
self
)
->
&
mut
T
{
manual_lock_generic
(
&
self
.lock
);
unsafe
{
manual_lock_generic
(
&
self
.lock
)
}
;
&
mut
*
self
.content
.get
()
unsafe
{
&
mut
*
self
.content
.get
()
}
}
}
/// Unlock the mutex, if it's locked.
/// Unlock the mutex, if it's locked.
pub
unsafe
fn
manual_unlock
(
&
self
)
{
pub
unsafe
fn
manual_unlock
(
&
self
)
{
manual_unlock_generic
(
&
self
.lock
)
unsafe
{
manual_unlock_generic
(
&
self
.lock
)
}
}
}
pub
fn
as_ptr
(
&
self
)
->
*
mut
T
{
pub
fn
as_ptr
(
&
self
)
->
*
mut
T
{
self
.content
.get
()
self
.content
.get
()
...
...
This diff is collapsed.
Click to expand it.
src/sync/waitval.rs
+
1
−
1
View file @
e73b891e
...
@@ -28,7 +28,7 @@ impl<T> Waitval<T> {
...
@@ -28,7 +28,7 @@ impl<T> Waitval<T> {
// SAFETY: Caller must ensure both (1) that the value has not yet been initialized, and (2)
// SAFETY: Caller must ensure both (1) that the value has not yet been initialized, and (2)
// that this is never run by more than one thread simultaneously.
// that this is never run by more than one thread simultaneously.
pub
unsafe
fn
post
(
&
self
,
value
:
T
)
{
pub
unsafe
fn
post
(
&
self
,
value
:
T
)
{
self
.value
.get
()
.write
(
MaybeUninit
::
new
(
value
));
unsafe
{
self
.value
.get
()
.write
(
MaybeUninit
::
new
(
value
))
}
;
self
.state
.store
(
1
,
Ordering
::
Release
);
self
.state
.store
(
1
,
Ordering
::
Release
);
crate
::
sync
::
futex_wake
(
&
self
.state
,
i32
::
MAX
);
crate
::
sync
::
futex_wake
(
&
self
.state
,
i32
::
MAX
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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