parent
23e655d7dd
commit
f5a5c08e5d
@ -816,6 +816,51 @@ mod openbsd {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||
#[inline]
|
||||
fn get_core_ids_helper() -> Result<Vec<CoreId>, Error> {
|
||||
solaris::get_core_ids()
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||
#[inline]
|
||||
fn set_for_current_helper(core_id: CoreId) -> Result<(), Error> {
|
||||
solaris::set_for_current(core_id)
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||
mod solaris {
|
||||
use alloc::vec::Vec;
|
||||
use std::thread::available_parallelism;
|
||||
|
||||
use super::CoreId;
|
||||
use crate::Error;
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
pub fn get_core_ids() -> Result<Vec<CoreId>, Error> {
|
||||
Ok((0..(usize::from(available_parallelism()?)))
|
||||
.into_iter()
|
||||
.map(|n| CoreId { id: n })
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
pub fn set_for_current(core_id: CoreId) -> Result<(), Error> {
|
||||
let result = unsafe {
|
||||
libc::processor_bind(
|
||||
libc::P_PID,
|
||||
libc::PS_MYID,
|
||||
core_id.id as i32,
|
||||
std::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
if result < 0 {
|
||||
Err(Error::unknown("Failed to processor_bind"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::thread::available_parallelism;
|
||||
|
@ -74,6 +74,7 @@ use core::{
|
||||
time::Duration,
|
||||
};
|
||||
#[cfg(all(unix, feature = "std"))]
|
||||
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
|
||||
use std::os::unix::io::AsRawFd;
|
||||
#[cfg(feature = "std")]
|
||||
use std::{
|
||||
@ -87,6 +88,7 @@ use std::{
|
||||
#[cfg(all(debug_assertions, feature = "llmp_debug", feature = "std"))]
|
||||
use backtrace::Backtrace;
|
||||
#[cfg(all(unix, feature = "std"))]
|
||||
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
|
||||
use nix::sys::socket::{self, sockopt::ReusePort};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -380,6 +382,7 @@ fn tcp_bind(port: u16) -> Result<TcpListener, Error> {
|
||||
let listener = TcpListener::bind((_LLMP_BIND_ADDR, port))?;
|
||||
|
||||
#[cfg(unix)]
|
||||
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
|
||||
socket::setsockopt(listener.as_raw_fd(), ReusePort, &true)?;
|
||||
|
||||
Ok(listener)
|
||||
|
@ -800,12 +800,22 @@ pub mod unix_shmem {
|
||||
|
||||
impl CommonUnixShMem {
|
||||
/// Create a new shared memory mapping, using shmget/shmat
|
||||
#[allow(unused_qualifications)]
|
||||
pub fn new(map_size: usize) -> Result<Self, Error> {
|
||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||
const SHM_R: libc::c_int = 0o400;
|
||||
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
|
||||
const SHM_R: libc::c_int = libc::SHM_R;
|
||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||
const SHM_W: libc::c_int = 0o200;
|
||||
#[cfg(not(any(target_os = "solaris", target_os = "illumos")))]
|
||||
const SHM_W: libc::c_int = libc::SHM_W;
|
||||
|
||||
unsafe {
|
||||
let os_id = shmget(
|
||||
libc::IPC_PRIVATE,
|
||||
map_size,
|
||||
libc::IPC_CREAT | libc::IPC_EXCL | libc::SHM_R | libc::SHM_W,
|
||||
libc::IPC_CREAT | libc::IPC_EXCL | SHM_R | SHM_W,
|
||||
);
|
||||
|
||||
if os_id < 0_i32 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user