goringbuf

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 0 Imported by: 0

README

go-ringbuf

Go GitHub tag (latest SemVer) GoDoc FOSSA Status Go Report Card Coverage Status

go-ringbuf provides a high-performance, lock-free circular queue (ring buffer) implementation in golang.

MPMC (multiple-producers and multiple consumers) enabled.

History

WIP:

  • english documentation not completed yet
  • documentation at: https:
v1.0.0

Last release for classical version.

Next release (v2) will move to go 1.18+ with generic enabled.

v0.9.1 @2022
  • review all codes
  • updated deps
  • review and solve uncertain misreport failed licenses
    • we have two deps: hedzr/errors and hedzr/log, and both them have no 3rd-party deps.
    • we have no more 3rd-party deps.
    • we assumed a free license under MIT (unified).

Getting Start

go get -v github.com/hedzr/go-ringbuf
Import
import "github.com/hedzr/go-ringbuf/fast"
Simple 1
import "github.com/hedzr/go-ringbuf/fast"

func main() {
	var err error
	var rb = fast.New(80)
	err = rb.Enqueue(3)
	errChk(err)
	
	var item interface{}
	item, err = rb.Dequeue()
	errChk(err)
	fmt.Printf("dequeue ok: %v\n", item)
}

func errChk(err error) {
	if err != nil {
		log.Fatal(err)
	}
}
Using Ring-Buffer as a fixed resource pool
func newRes() *Res{...}

var rb fast.RingBuffer

func initFunc() (err error) {
  const maxSize = 16
  
  if rb = fast.New(uint32(maxSize)); rb == nil {
		err = errors.New("cannot create fast.RingBuffer")
		return
	}

    // CapReal() will be available since v0.8.8, or replace it with Cap() - 1
	for i := uint32(0); i < rb.CapReal(); i++ {
		if err = rb.Enqueue(newRes()); err != nil {
			return
		}
	}
}

func loopFor() {
  var err error
  for {
    it, err := rb.Dequeue()
    checkErr(err)
    if res, ok := it.(*Res); ok {
      // do stuff with `res`, and put it back into ring-buffer
      err = rb.Enqueue(it)
    }
  }
}

Contrib

Welcome

LICENSE

MIT

FOSSA Status

Documentation

Overview

Package goringbuf provides a lock-free ring-buffer/circular-queue (in ringbuf/fast).

Index

Constants

View Source
const (
	// AppName const
	AppName = "ringbuf"
	// Version const
	Version = "1.0.0"
	// VersionInt const
	VersionInt = 0x010000
)

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
Package fast provides a lock-free ring-buffer/circular-queue
Package fast provides a lock-free ring-buffer/circular-queue

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL