Skip to content

Instantly share code, notes, and snippets.

@soheilhy
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soheilhy/ef7b04d220a2b57e5629 to your computer and use it in GitHub Desktop.
Save soheilhy/ef7b04d220a2b57e5629 to your computer and use it in GitHub Desktop.
Task ring buffer
// TaskRing is an efficient, gob-compatible ring buffer for Tasks.
// TaskRing always wastes one element.
type TaskRing struct {
...
Stats Stats
}
// Stats represents the statistics of the task ring buffer.
type Stats struct {
Deque uint64 // Deque represents the total nubmer of dequeued tasks.
Enque uint64 // Enque represents the total nubmer of enqued tasks.
...
}
// Enque enqueues a task in the ring buffer.
func (r *TaskRing) Enque(t Task) {...}
// Deque dequeues a task from the ring.
func (r *TaskRing) Deque() (t Task, ok bool) {...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment