Skip to content
Merged
Changes from all commits
Commits
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
16 changes: 5 additions & 11 deletions library/std/src/sys/pal/windows/winsock.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use super::c;
use crate::ffi::c_int;
use crate::sync::atomic::Atomic;
use crate::sync::atomic::Ordering::{AcqRel, Relaxed};
use crate::sync::Once;
use crate::{io, mem};

static WSA_STARTED: Atomic<bool> = Atomic::<bool>::new(false);
static WSA_INIT: Once = Once::new();

/// Checks whether the Windows socket interface has been started already, and
/// if not, starts it.
#[inline]
pub fn startup() {
if !WSA_STARTED.load(Relaxed) {
wsa_startup();
}
// Make sure to only call `WSAStartup` once, because it's not thread-safe
// on Wine: https://bugs.winehq.org/show_bug.cgi?id=60084.
WSA_INIT.call_once_force(|_| wsa_startup());
}

#[cold]
Expand All @@ -24,11 +23,6 @@ fn wsa_startup() {
&mut data,
);
assert_eq!(ret, 0);
if WSA_STARTED.swap(true, AcqRel) {
// If another thread raced with us and called WSAStartup first then call
// WSACleanup so it's as though WSAStartup was only called once.
c::WSACleanup();
}
}
}

Expand Down
Loading