pub struct Sel<const N: XwSz>where
    [XwBmp; { _ }]: Sized,{ /* private fields */ }Expand description
信号选择器对象结构体
Implementations§
source§impl<const N: XwSz> Sel<N>where
    [XwBmp; { _ }]: Sized,
 
impl<const N: XwSz> Sel<N>where
    [XwBmp; { _ }]: Sized,
sourcepub fn select(&self, msk: &Bmp<N>) -> Result<Bmp<N>, SelError>
 
pub fn select(&self, msk: &Bmp<N>) -> Result<Bmp<N>, SelError>
等待信号选择器中的 选择信号
- 当没有同步对象向信号选择器发送 选择信号 时,线程会阻塞等待。
- 当 任意 同步对象向信号选择器发送 选择信号 时,线程被唤醒,然后返回 Bmp<N>。
- 当线程阻塞等待被中断时,返回 SelError::Interrupt。
§参数说明
- msk: 事件的位图掩码
§上下文
- 线程
§错误码
- SelError::NotInit信号选择器没有初始化
- SelError::Interrupt等待被中断
- SelError::NotThreadContext不在线程上下文内
§示例
use xwrust::xwbmp::*;
use xwrust::xwos::sync::sel::*;
pub fn xwrust_example_sel() {
    let sel = Sel::<8>::new();
    sel.init();
    // ...省略bind过程...
    let msk = Bmp::<8>::new();
    msk.s1all(); // 设置掩码
    let res = sel.select(msk);
    match res {
        Ok(t) => { // 等待成功, `t` 为 **选择信号** 的位图
        },
        Err(e) => { // 等待失败, `e` 为 `SelError`
        },
    }
}sourcepub fn select_to(&self, msk: &Bmp<N>, to: XwTm) -> Result<Bmp<N>, SelError>
 
pub fn select_to(&self, msk: &Bmp<N>, to: XwTm) -> Result<Bmp<N>, SelError>
限时等待所有线程到达栅栏
- 当信号选择器中的线程数量小于指定数量,线程会阻塞等待,等待时会指定一个唤醒时间点。
- 当信号选择器中的线程数量达到指定数量,线程被唤醒,然后返回 Bmp<N>。
- 当线程阻塞等待被中断时,返回 SelError::Interrupt。
- 当到达指定的唤醒时间点,线程被唤醒,并返回 SelError::Timedout。
§参数说明
- msk: 事件的位图掩码
- to: 期望唤醒的时间点
§上下文
- 线程
§错误码
- SelError::NotInit信号选择器没有初始化
- SelError::Interrupt等待被中断
- SelError::Timedout等待超时
- SelError::NotThreadContext不在线程上下文内
§示例
use xwrust::xwbmp::*;
use xwrust::xwos::sync::sel::*;
pub fn xwrust_example_sel() {
    let sel = Sel::<8>::new();
    sel.init();
    // ...省略bind过程...
    let msk = Bmp::<8>::new();
    msk.s1all(); // 设置掩码
    let res = sel.select_to(msk, xwtm::ft(xwtm::s(3)));
    match res {
        Ok(t) => { // 等待成功, `t` 为 **选择信号** 的位图
        },
        Err(e) => { // 等待失败, `e` 为 `SelError`
        },
    }
}sourcepub fn tryselect(&self, msk: &Bmp<N>) -> Result<Bmp<N>, SelError>
 
pub fn tryselect(&self, msk: &Bmp<N>) -> Result<Bmp<N>, SelError>
检测信号选择器中是否有 选择信号
- 当检测到 任意 同步对象向信号选择器发送 选择信号 时,立即返回 Bmp<N>。
- 当没有同步对象向信号选择器发送 选择信号 时,立即返回 SelError::NoSignal。
§参数说明
- msk: 事件的位图掩码
§上下文
- 线程
§错误码
- SelError::NotInit信号选择器没有初始化
- SelError::NoSignal没有检测到 选择信号
§示例
use xwrust::xwbmp::*;
use xwrust::xwos::sync::sel::*;
pub fn xwrust_example_sel() {
    let sel = Sel::<8>::new();
    sel.init();
    // ...省略bind过程...
    let msk = Bmp::<8>::new();
    msk.s1all(); // 设置掩码
    let res = sel.tryselect(msk);
    match res {
        Ok(t) => { // 等待成功, `t` 为 **选择信号** 的位图
        },
        Err(e) => { // 等待失败, `e` 为 `SelError`
        },
    }
}sourcepub fn bind<'a, const M: XwSz>(
    &'a self,
    dst: &'a Sel<M>,
    pos: XwSq,
) -> Result<SelSel<'a, N, M>, SelError>where
    [XwBmp; { _ }]: Sized,
 
pub fn bind<'a, const M: XwSz>(
    &'a self,
    dst: &'a Sel<M>,
    pos: XwSq,
) -> Result<SelSel<'a, N, M>, SelError>where
    [XwBmp; { _ }]: Sized,
绑定源信号选择器 src 到目的信号选择器 dst
- 源信号选择器 src绑定到目的信号选择器dst上时, 采用 非独占 的方式进行绑定。
- 绑定成功,通过 Ok()返回SelSel<'a, N, M>。
- 如果位置已被其他 同步对象 以 独占 的方式占领,通过 Err()返回SelError::SelPosBusy。
- 当指定的位置超出范围(例如 dst只有8个位置,用户偏偏要绑定到位置9 ),通过Err()返回SelError::OutOfSelPos。
- 重复绑定,通过 Err()返回SelError::AlreadyBound。
SelSel<'a, N, M> 中包含绑定信息。 SelSel<'a, N, M> 与 src 与 dst 具有相同的生命周期约束 'a 。
SelSel::selected() 可用来判断 src 是否被选择。当 SelSel<'a, N, M> drop() 时,会自动将 src 从 dst 解绑。
§参数说明
- dst: 目的信号选择器的引用
- pos: 位置
§上下文
- 任意
§错误码
- SelError::OutOfSelPos信号选择器的位置超出范围
- SelError::AlreadyBound信号选择器已经绑定
- SelError::SelPosBusy信号选择器的位置被占用
§示例
pub fn xwrust_example_sel() {
    // ...省略...
    let sel0 = Arc::new(Sel::<8>::new());
    sel0.init();
    let sel0sel = match sel0.bind(&sel, 0) {
        Ok(s) => { // 绑定成功,`s` 为 `SelSel`
            s
        },
        Err(e) => { // 绑定失败,`e` 为 `SelError`
            return;
        }
    };
    // ...省略...
}