shared-mem-queue 0.4.0

Single-writer single-reader queues which can be used for inter-processor-communication in a shared memory region
Documentation
mod shm;

use shared_mem_queue::byte_queue::ByteQueue;
use shared_mem_queue::msg_queue::MsgQueue;
use shm::ShmHandle;

use libc::{O_CREAT, O_RDWR, O_TRUNC};

const SHM_MODE_WR: libc::mode_t = 0o666;
const SHM_NAME_WR: &str = "shm_msg_queue";
const SIZE: usize = 128;

fn main() {
    let mut shm_handle =
        ShmHandle::new(SHM_NAME_WR, SIZE, O_CREAT | O_RDWR | O_TRUNC, SHM_MODE_WR).unwrap();
    let prefix: &[u8] = &[7, 7, 7, 7];
    let rx_buf: [u8; 21] = [0; 21]; // not used with write operations
    let mut msg_queue = MsgQueue::new(
        unsafe { ByteQueue::create(shm_handle.as_mut_ptr_u8(), SIZE) },
        prefix,
        rx_buf,
    );

    let mut data: [u8; 5] = [1, 2, 3, 4, 5];
    loop {
        if let Err(err) = msg_queue.write_or_fail(&data) {
            println!("{err}");
        } else {
            println!("msg written into the queue");
            data[0] = data[0].wrapping_add(1);
        }
        std::thread::sleep(std::time::Duration::from_millis(100));
    }
}