MessageQueue

Struct MessageQueue 

Source
pub struct MessageQueue {
    state: Mutex<QueueState>,
    send_waiters: SpinLock<WaitQueue>,
    recv_waiters: SpinLock<WaitQueue>,
    max_bytes: usize,
}
Expand description

进程间消息队列(支持阻塞的发送/接收)

Fields§

§state: Mutex<QueueState>

队列状态:消息与当前字节数

§send_waiters: SpinLock<WaitQueue>

等待发送(队列满)的进程

§recv_waiters: SpinLock<WaitQueue>

等待接收(队列空)的进程

§max_bytes: usize

队列的最大容量(字节)

Implementations§

Source§

impl MessageQueue

Source

pub fn new() -> Self

创建一个新的进程间消息队列

Source

pub fn send(&self, msg: Message)

发送消息(阻塞直到有空间)

Source

pub fn recv(&self) -> Message

接收任意类型的消息(阻塞直到有消息)

Source

pub fn recv_by_type(&self, mtype: i32) -> Message

按类型接收(阻塞直到有匹配类型)

Source

pub fn try_send(&self, msg: Message) -> bool

非阻塞尝试:返回是否成功发送

Source

pub fn try_recv(&self) -> Option<Message>

非阻塞尝试接收

Source

pub fn try_recv_by_type(&self, mtype: i32) -> Option<Message>

非阻塞按类型接收

Source

pub fn used_bytes(&self) -> usize

查询当前已用字节数

Source

pub fn set_max_bytes(&mut self, max: usize)

设置最大容量

Auto Trait Implementations§

§

impl !Freeze for MessageQueue

§

impl !RefUnwindSafe for MessageQueue

§

impl Send for MessageQueue

§

impl Sync for MessageQueue

§

impl Unpin for MessageQueue

§

impl !UnwindSafe for MessageQueue

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.