Code Monkey home page Code Monkey logo

mpmc-queue's Introduction

mpmc-queue

Build Status

multiple-producer-multiple-consumer queue for emacs (>= 26.0).

Installation

You can start using this by putting mpmc-queue.el in your load-path.

How to Use

You can create a mpmc queue with mpmc-queue--create function, and can enqueue or dequeue elements by mpmc-queue-put or mpmc-queue-get functions. There is also mpmc-queue-peek function that returns the first element without removing it from the queue:

;; queue creation
(setq-local q (mpmc-queue--create))

;; basic queue operations
(mpmc-queue-put q 1)
(mpmc-queue-peek q) ;; => 1
(mpmc-queue-get q) ;; => 1

(mpmc-queue-empty-p q) ;; => t

;; non-blocking vs. blocking
(mpmc-queue-get q t) ;; => nil
(mpmc-queue-get q) ;; => blocks until an element is available in the queue

mpmc-queue-get and mpmc-queue-peek functions take one optional argument (non-blocking). If this optional argument is t and the queue is empty, these functions return nil immediately. If the argument is nil and the queue is empty, these block until an element is available in the queue.

MPMC Queue Structure

This queue has 3 fields:

  • internal-queue: the internal queue defined in queue.el
  • mutex: the mutex associated with this queue.
  • non-empty-condition: the condition variable used to notify changes from the empty state to a non-empty state.

There is macro mpmc-queue--with-mutex which runs the given body while holding the mutex of a mpmc queue:

(setq-local q (mpmc-queue--create))
(mpmc-queue--with-mutex q
    ;; do whatever you want with the queue
    (...)
    )

mpmc-queue's People

Contributors

smizoe avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

emacsmirror

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.