summaryrefslogtreecommitdiffstats
path: root/library/std/src/sys/solid
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/sys/solid')
-rw-r--r--library/std/src/sys/solid/net.rs11
-rw-r--r--library/std/src/sys/solid/thread_local_dtor.rs15
2 files changed, 15 insertions, 11 deletions
diff --git a/library/std/src/sys/solid/net.rs b/library/std/src/sys/solid/net.rs
index 6adced787..1eae0fc06 100644
--- a/library/std/src/sys/solid/net.rs
+++ b/library/std/src/sys/solid/net.rs
@@ -233,12 +233,15 @@ impl Socket {
}
}
+ pub fn connect(&self, addr: &SocketAddr) -> io::Result<()> {
+ let (addr, len) = addr.into_inner();
+ cvt(unsafe { netc::connect(self.0.raw(), addr.as_ptr(), len) })?;
+ Ok(())
+ }
+
pub fn connect_timeout(&self, addr: &SocketAddr, timeout: Duration) -> io::Result<()> {
self.set_nonblocking(true)?;
- let r = unsafe {
- let (addr, len) = addr.into_inner();
- cvt(netc::connect(self.0.raw(), addr.as_ptr(), len))
- };
+ let r = self.connect(addr);
self.set_nonblocking(false)?;
match r {
diff --git a/library/std/src/sys/solid/thread_local_dtor.rs b/library/std/src/sys/solid/thread_local_dtor.rs
index bad14bb37..26918a4fc 100644
--- a/library/std/src/sys/solid/thread_local_dtor.rs
+++ b/library/std/src/sys/solid/thread_local_dtor.rs
@@ -4,14 +4,13 @@
// Simplify dtor registration by using a list of destructors.
use super::{abi, itron::task};
-use crate::cell::Cell;
-use crate::mem;
+use crate::cell::{Cell, RefCell};
#[thread_local]
static REGISTERED: Cell<bool> = Cell::new(false);
#[thread_local]
-static mut DTORS: Vec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new();
+static DTORS: RefCell<Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>> = RefCell::new(Vec::new());
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
if !REGISTERED.get() {
@@ -22,18 +21,20 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
REGISTERED.set(true);
}
- let list = unsafe { &mut DTORS };
- list.push((t, dtor));
+ match DTORS.try_borrow_mut() {
+ Ok(mut dtors) => dtors.push((t, dtor)),
+ Err(_) => rtabort!("global allocator may not use TLS"),
+ }
}
pub unsafe fn run_dtors() {
- let mut list = mem::take(unsafe { &mut DTORS });
+ let mut list = DTORS.take();
while !list.is_empty() {
for (ptr, dtor) in list {
unsafe { dtor(ptr) };
}
- list = mem::take(unsafe { &mut DTORS });
+ list = DTORS.take();
}
}