kernel/object/
event.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use super::{KernelObject, KernelObjectId, KernelObjectType};
use alloc::sync::Arc;
use core::sync::atomic::{AtomicBool, Ordering};

#[derive(Debug)]
pub struct Event {
    pub id: KernelObjectId,
    pub signalled: AtomicBool,
}

impl Event {
    pub fn new() -> Arc<Event> {
        Arc::new(Event { id: super::alloc_kernel_object_id(), signalled: AtomicBool::new(false) })
    }

    pub fn signal(&self) {
        // TODO: ordering?
        self.signalled.store(true, Ordering::SeqCst);
    }

    pub fn clear(&self) {
        // TODO: ordering?
        self.signalled.store(false, Ordering::SeqCst);
    }
}

impl KernelObject for Event {
    fn id(&self) -> KernelObjectId {
        self.id
    }

    fn typ(&self) -> KernelObjectType {
        KernelObjectType::Event
    }
}