Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #78001

Merged
merged 64 commits into from
Oct 16, 2020
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a020142
Refactor io/buffered.rs into submodules
Lucretiel Sep 11, 2020
96229f0
move buffered.rs to mod.rs
Lucretiel Sep 11, 2020
6d75cdf
Added updated compiler diagnostic
Lucretiel Sep 15, 2020
da700cb
Stabilize move_ref_pattern
Amjad50 Aug 30, 2020
afb9eeb
Disabled error `E0007` from rustc_error_codes
Amjad50 Aug 30, 2020
c4280af
Retry fix error reporting suggestions
Lucretiel Sep 17, 2020
0b923d3
add `str::{Split,RSplit}::as_str` methods
WaffleLapkin Oct 1, 2020
4747215
add `str::{SplitN, RSplitN, SplitTerminator, RSplitTerminator}::as_st…
WaffleLapkin Oct 1, 2020
076514c
add `str::SplitInclusive::as_str` method
WaffleLapkin Oct 1, 2020
f84f01c
Use futex-based thread-parker for Wasm32.
m-ou-se Oct 6, 2020
54a71e8
For backtrace, use StaticMutex instead of a raw sys Mutex.
m-ou-se Oct 7, 2020
e6d61ad
Use slice_as_mut_ptr instead of first_ptr_mut.
m-ou-se Oct 7, 2020
0f26578
Get rid of UnsafeCell<MaybeUninit>s in cloudabi mutex.
m-ou-se Oct 7, 2020
41066be
Get rid of UnsafeCell in cloudabi rwlock.
m-ou-se Oct 7, 2020
060e8cb
Get rid of raw pointers and UnsafeCell in cloudabi condvar.
m-ou-se Oct 7, 2020
b3be11e
Formatting.
m-ou-se Oct 7, 2020
6f0544a
Simplify doc-cfg rendering based on the current context
Nemo157 Oct 6, 2020
17eb8d8
ICEs should print the top of the query stack
hosseind75 Sep 19, 2020
20ea929
run full query stack print just when RUST_BACKTRACE is set
hosseind75 Sep 19, 2020
7ccca35
fix invalid-punct-ident-1 test
hosseind75 Sep 19, 2020
d6d4388
add filter regexes to load-panic-backtraces test
hosseind75 Sep 20, 2020
d60b7e2
fix show we're just showing... message instead of the end of query st…
hosseind75 Sep 23, 2020
6e7e4ac
fix clippy custom_ice_message test
hosseind75 Sep 25, 2020
15663a4
add new line
hosseind75 Sep 28, 2020
2124e9b
rebase with master
hosseind75 Sep 29, 2020
2b91b7f
ICEs should print the top of the query stack
hosseind75 Sep 19, 2020
01f838a
run full query stack print just when RUST_BACKTRACE is set
hosseind75 Sep 19, 2020
2bfdd64
change approach and run ui tests
hosseind75 Sep 19, 2020
b6e9f08
show a message when we are showing limited slice of query stack
hosseind75 Sep 19, 2020
3c56ba5
fix invalid-punct-ident-1 test
hosseind75 Sep 19, 2020
d1e3059
add filter regexes to load-panic-backtraces test
hosseind75 Sep 20, 2020
6c0f06a
fix show we're just showing... message instead of the end of query st…
hosseind75 Sep 23, 2020
c61d95b
remove new line
hosseind75 Sep 29, 2020
998186e
revert deleted new line
hosseind75 Oct 3, 2020
42ebae3
delete const-pat-ice test stderr
Oct 6, 2020
73d8f00
change condition for end of query stack message
Oct 8, 2020
7280f6a
rustc_parse: correct span on cast expr with attrs
calebcartwright Oct 10, 2020
4e82da4
rustc_parse: correct span on range expr with attrs
calebcartwright Oct 12, 2020
4e263fe
Add test-examples for Cfg::simplify_with
Nemo157 Oct 13, 2020
4409cb2
Make portability log at debug level
Nemo157 Oct 13, 2020
5875657
Fix comment about non-reentrant StaticMutex::lock().
m-ou-se Oct 7, 2020
44a2af3
Remove lifetime from StaticMutex and assume 'static.
m-ou-se Oct 7, 2020
a22cd05
BTreeMap: making PartialCmp/PartialEq explicit and tested
ssomers Oct 14, 2020
46cc889
fix stderr file of clippy/custom_ice_message test
Oct 14, 2020
9752787
mangling: non-monomorphic `#[rustc_symbol_name]`
davidtwco Aug 18, 2020
fbdfe2c
mangling: encode all impl parameters
davidtwco Aug 24, 2020
95daa06
fix off-by-one in parameter spans
euclio Sep 26, 2020
14b2d16
ensure arguments are included in count mismatch span
euclio Sep 24, 2020
1c03f6d
Fix intra doc link for needs_drop
Manishearth Oct 15, 2020
7bd6403
fill in the tracking issue
WaffleLapkin Oct 15, 2020
075f2bf
Rollup merge of #75023 - euclio:argument-span, r=estebank
Dylan-DPC Oct 16, 2020
977df43
Rollup merge of #75265 - WaffleLapkin:str_split_as_str, r=dtolnay
Dylan-DPC Oct 16, 2020
1643fd8
Rollup merge of #75675 - davidtwco:symbol-mangling-impl-params, r=eddyb
Dylan-DPC Oct 16, 2020
5acb7f1
Rollup merge of #76084 - Lucretiel:split-buffered, r=dtolnay
Dylan-DPC Oct 16, 2020
85dbb03
Rollup merge of #76119 - Amjad50:stabilizing-move_ref_pattern, r=niko…
Dylan-DPC Oct 16, 2020
0e4d196
Rollup merge of #77493 - hosseind88:ICEs_should_always_print_the_top_…
Dylan-DPC Oct 16, 2020
dcf972a
Rollup merge of #77619 - fusion-engineering-forks:wasm-parker, r=dtolnay
Dylan-DPC Oct 16, 2020
085399f
Rollup merge of #77646 - fusion-engineering-forks:use-static-mutex, r…
Dylan-DPC Oct 16, 2020
b183ef2
Rollup merge of #77648 - fusion-engineering-forks:static-mutex, r=dto…
Dylan-DPC Oct 16, 2020
9b8c0eb
Rollup merge of #77657 - fusion-engineering-forks:cleanup-cloudabi-sy…
Dylan-DPC Oct 16, 2020
71b0ea6
Rollup merge of #77672 - Nemo157:simplify-cfg, r=jyn514
Dylan-DPC Oct 16, 2020
9d8bf44
Rollup merge of #77780 - calebcartwright:cast-expr-attr-span, r=oli-obk
Dylan-DPC Oct 16, 2020
b64b5fa
Rollup merge of #77935 - ssomers:btree_cleanup_1, r=Mark-Simulacrum
Dylan-DPC Oct 16, 2020
e688b4d
Rollup merge of #77980 - Manishearth:needs-drop-intra, r=jyn514
Dylan-DPC Oct 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Get rid of UnsafeCell<MaybeUninit>s in cloudabi mutex.
  • Loading branch information
m-ou-se committed Oct 7, 2020
commit 0f26578f2e2e41c51279f3b2bd967785241d316d
52 changes: 24 additions & 28 deletions library/std/src/sys/cloudabi/mutex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::cell::UnsafeCell;
use crate::cell::Cell;
use crate::mem;
use crate::mem::MaybeUninit;
use crate::sync::atomic::{AtomicU32, Ordering};
Expand Down Expand Up @@ -50,28 +50,23 @@ impl Mutex {
}

pub struct ReentrantMutex {
lock: UnsafeCell<MaybeUninit<AtomicU32>>,
recursion: UnsafeCell<MaybeUninit<u32>>,
lock: AtomicU32,
recursion: Cell<u32>,
}

unsafe impl Send for ReentrantMutex {}
unsafe impl Sync for ReentrantMutex {}

impl ReentrantMutex {
pub const unsafe fn uninitialized() -> ReentrantMutex {
ReentrantMutex {
lock: UnsafeCell::new(MaybeUninit::uninit()),
recursion: UnsafeCell::new(MaybeUninit::uninit()),
}
ReentrantMutex { lock: AtomicU32::new(abi::LOCK_UNLOCKED.0), recursion: Cell::new(0) }
}

pub unsafe fn init(&self) {
*self.lock.get() = MaybeUninit::new(AtomicU32::new(abi::LOCK_UNLOCKED.0));
*self.recursion.get() = MaybeUninit::new(0);
}
pub unsafe fn init(&self) {}

pub unsafe fn try_lock(&self) -> bool {
// Attempt to acquire the lock.
let lock = (*self.lock.get()).as_mut_ptr();
let recursion = (*self.recursion.get()).as_mut_ptr();
if let Err(old) = (*lock).compare_exchange(
if let Err(old) = self.lock.compare_exchange(
abi::LOCK_UNLOCKED.0,
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
Ordering::Acquire,
Expand All @@ -80,22 +75,22 @@ impl ReentrantMutex {
// If we fail to acquire the lock, it may be the case
// that we've already acquired it and may need to recurse.
if old & !abi::LOCK_KERNEL_MANAGED.0 == __pthread_thread_id.0 | abi::LOCK_WRLOCKED.0 {
*recursion += 1;
self.recursion.set(self.recursion.get() + 1);
true
} else {
false
}
} else {
// Success.
assert_eq!(*recursion, 0, "Mutex has invalid recursion count");
assert_eq!(self.recursion.get(), 0, "Mutex has invalid recursion count");
true
}
}

pub unsafe fn lock(&self) {
if !self.try_lock() {
// Call into the kernel to acquire a write lock.
let lock = self.lock.get();
let lock = &self.lock as *const AtomicU32;
let subscription = abi::subscription {
type_: abi::eventtype::LOCK_WRLOCK,
union: abi::subscription_union {
Expand All @@ -116,17 +111,17 @@ impl ReentrantMutex {
}

pub unsafe fn unlock(&self) {
let lock = (*self.lock.get()).as_mut_ptr();
let recursion = (*self.recursion.get()).as_mut_ptr();
assert_eq!(
(*lock).load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
self.lock.load(Ordering::Relaxed) & !abi::LOCK_KERNEL_MANAGED.0,
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
"This mutex is locked by a different thread"
);

if *recursion > 0 {
*recursion -= 1;
} else if !(*lock)
let r = self.recursion.get();
if r > 0 {
self.recursion.set(r - 1);
} else if !self
.lock
.compare_exchange(
__pthread_thread_id.0 | abi::LOCK_WRLOCKED.0,
abi::LOCK_UNLOCKED.0,
Expand All @@ -137,19 +132,20 @@ impl ReentrantMutex {
{
// Lock is managed by kernelspace. Call into the kernel
// to unblock waiting threads.
let ret = abi::lock_unlock(lock as *mut abi::lock, abi::scope::PRIVATE);
let ret = abi::lock_unlock(
&self.lock as *const AtomicU32 as *mut abi::lock,
abi::scope::PRIVATE,
);
assert_eq!(ret, abi::errno::SUCCESS, "Failed to unlock a mutex");
}
}

pub unsafe fn destroy(&self) {
let lock = (*self.lock.get()).as_mut_ptr();
let recursion = (*self.recursion.get()).as_mut_ptr();
assert_eq!(
(*lock).load(Ordering::Relaxed),
self.lock.load(Ordering::Relaxed),
abi::LOCK_UNLOCKED.0,
"Attempted to destroy locked mutex"
);
assert_eq!(*recursion, 0, "Recursion counter invalid");
assert_eq!(self.recursion.get(), 0, "Recursion counter invalid");
}
}