Skip to main content

yule_gpu/
buffer.rs

1use crate::BufferHandle;
2use std::collections::HashMap;
3use std::sync::atomic::{AtomicU64, Ordering};
4
5static NEXT_HANDLE: AtomicU64 = AtomicU64::new(1);
6
7pub fn next_buffer_handle() -> BufferHandle {
8    BufferHandle(NEXT_HANDLE.fetch_add(1, Ordering::Relaxed))
9}
10
11pub struct BufferPool {
12    allocated: HashMap<u64, AllocatedBuffer>,
13    total_bytes: u64,
14    max_bytes: u64,
15}
16
17struct AllocatedBuffer {
18    size: usize,
19    in_use: bool,
20}
21
22impl BufferPool {
23    pub fn new(max_bytes: u64) -> Self {
24        Self {
25            allocated: HashMap::new(),
26            total_bytes: 0,
27            max_bytes,
28        }
29    }
30
31    pub fn total_allocated(&self) -> u64 {
32        self.total_bytes
33    }
34
35    pub fn max_capacity(&self) -> u64 {
36        self.max_bytes
37    }
38}