/zig-xbeam

A very partial re-implementation of the rust crate crossbeam.

Primary LanguageZigMIT LicenseMIT

zig-xbream

This repo is a very partial (pull requests welcome) re-implementation of the rust crate crossbeam.

Only the following types are implemented:

Data structures

  • xbeam.queue.ArrayQueue - a bounded MPMC queue that allocates a fixed-capacity buffer on construction.
  • xbeam.queue.ArrayQueueNoAlloc - an implementation of ArrayQueue that does not allocate.

Utilities

  • xbeam.utils.Backoff - for exponential backoff in spin loops.

  • xbeam.utils.CACHE_LINE_LENGTH - replacement for the rust CachePadded, used like this:

    var aligned: usize align(xbeam.utils.CACHE_LINE_LENGTH) = 0;

Contributions are welcome!

How to use

Download the repo somehow then either:

Use a package manager

Add as package in build.zig

  • To build.zig add:

    exe.addPackagePath("xbeam", "zig-xbeam/src/index.zig"); // or whatever the path is
  • Then the package is available within any zig file:

    const xbeam = @import("xbeam");

Import directly

In any zig file add:

const xbeam = @import("../zig-xbeam/src/index.zig"); // or whatever the path is from *that* file