Giter Club home page Giter Club logo

bounded-spsc-queue's People

Contributors

andrewcsmith avatar bobo1239 avatar chengchangwu avatar eeeeeta avatar huonw avatar joelreymont avatar koverstreet avatar nanotech avatar nhynes avatar oli-obk avatar polyfractal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bounded-spsc-queue's Issues

Allocator API changed again on 1.30

Classic nightly, moving out from under you all the time. Anyway, this fails to build again on 1.30.

error[E0425]: cannot find function oom in module alloc
   --> ...\github.com-1ecc6299db9ec823\bounded-spsc-queue-0.3.0\src\lib.rs:351:260.3.0\src\lib.rs:351:26
    |
351 |         Err(_) => alloc::oom(),
    |                          ^^^ not found in alloc

   Compiling winapi v0.3.6                                                                         e
error[E0599]: no method named as_opaque found for type std::ptr::NonNull<T> in the current scop0.3.0\src\lib.rs:256:40e
   --> ...\github.com-1ecc6299db9ec823\bounded-spsc-queue-0.3.0\src\lib.rs:256:40
    |
256 |             Global.dealloc(self.buffer.as_opaque(), layout);
    |                                        ^^^^^^^^^

error: aborting due to 2 previous errors

Some errors occurred: E0425, E0599.

Remove dependency on nightly rust

Specifically:

  • UnsafeCell can be used to emulate !Sync
  • Vec may be used instead of manually using buffer + capacity + allocated_size (and depending on liballoc)

Don't panic on OOM allocation

Currently, if you try to request too much memory for the queue and allocation fails, we throw an OOM panic. That's pretty unfriendly :)

Instead, we should return a Result with the proper error so the user can decide what to do.

Allow stack-allocated queues

I'm getting into realtime embedded systems, and it would be fantastic to use your queue with a stack-allocated array. If we could pass in a pointer or a mutable slice or something along those lines that would basically do it for us. (This also seems like something that could totally be feature-gated, as it's probably not particularly often-used.)

Bad sync impl

The line in question:
unsafe impl<T: Sync> Sync for Buffer<T> {}

So, as far as I know this should line should be removed. Buffer inherits !Send and !Sync from the *mut T. Marking it as Sync is unsafe because it requires Buffer to implement thread safety itself, from any number of threads accessing any of its functions. Buffer itself is obviously not safe to be marked as Sync because try_push/try_pop for example will have inconsistencies if multiple threads call either one at once. Buffer's logic only guarantees one thread calling the consumer side (try_pop) of things and one thread calling the producer side (try_push) of things.

Arc is only Send and Sync if the underlying type being wrapped is also Send and Sync. The unsafe Sync marker on Buffer does not change the auto traits of Arc because since Buffer is not Send, Arc can be neither Send or Sync.

On top of all of this, Buffer should not be marked as pub in the first place since you cannot directly access it anyway.

Feature request: force-push

In low-latency applications, it's often desirable to drop old items from the queue in favor of newer items. A suitable interface might be something like:

fn force_push(&self, v: T) -> option<T>

where the return value is None or, if the oldest element was dropped, Some(old_value).

Such a function would be non-blocking, of course.

Producer and Consumer should opt-out of Sync

Right now Producer and Consumer are Sync, which allows the user to call try_{push, pop} from multiple threads at once, thus violating the single-consumer-single-producer property and possibly causing memory unsafety.

cc @gankro didn't see anything else obvious

Option to push + drop old data

I'm working on some audio programming applications where I'd actually like to drop the old data in the queue (and still push), rather than drop the new stuff (and never push it). Would it be possible to implement a version of this method on the Producer?

This is a very common application in audio programming -- we always want to update the buffer with the newest data, even if no one's listening -- so it would be great to have available in a library like this one.

Build fails on latest nightly.

Looks like the unstable heap API updated.

error[E0308]: mismatched types
   --> C:\Users\Mooma\.cargo\registry\src\github.com-1ecc6299db9ec823\bounded-spsc-queue-0.2.0\src\lib.rs:262:26
    |
262 |             Heap.dealloc(self.buffer as *mut u8, layout);
    |                          ^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::ptr::NonNull`, found *-ptr
    |
    = note: expected type `std::ptr::NonNull<std::heap::Opaque>`
               found type `*mut u8`

error[E0599]: no method named `oom` found for type `std::heap::Global` in the current scope
   --> C:\Users\Mooma\.cargo\registry\src\github.com-1ecc6299db9ec823\bounded-spsc-queue-0.2.0\src\lib.rs:350:24
    |
350 |         Err(e) => Heap.oom(e),
    |                        ^^^

error[E0605]: non-primitive cast: `std::ptr::NonNull<std::heap::Opaque>` as `*mut T`
   --> C:\Users\Mooma\.cargo\registry\src\github.com-1ecc6299db9ec823\bounded-spsc-queue-0.2.0\src\lib.rs:349:20
    |
349 |         Ok(ptr) => ptr as *mut T,
    |                    ^^^^^^^^^^^^^
    |
    = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait

error: aborting due to 3 previous errors

Some errors occurred: E0308, E0599, E0605.
For more information about an error, try `rustc --explain E0308`.
error: Could not compile `bounded-spsc-queue`.
warning: build failed, waiting for other jobs to finish...
error: build failed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.