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
#![allow(unused)]

use arraydeque::ArrayDeque;

use super::{scheduler::APPS, Scheduler};

/// Semaphore used for the synchronization of threads.
///
/// Other than the spinlock, this semaphore can put threads to sleep and wake them up.
#[derive(Debug)]
pub struct Semaphore {
    counter: usize,
    waiting: ArrayDeque<usize, APPS>,
}

impl Semaphore {
    // Initialize the `counter` with provided value
    pub const fn new(counter: usize) -> Self {
        todo!()
    }
    /// Get the current value of the counter
    pub fn count(&self) -> usize {
        self.counter
    }
    /// Wait for access to the critical area
    pub fn wait(&mut self, scheduler: &mut Scheduler) {
        todo!("BSB A6")
    }
    /// Leave the critical area
    pub fn signal(&mut self, scheduler: &mut Scheduler) {
        todo!("BSB A6")
    }
}