Skip to content

Instantly share code, notes, and snippets.

@taotetek
Created December 15, 2015 01:45
Show Gist options
  • Save taotetek/88cd49d0d3cd206ed26c to your computer and use it in GitHub Desktop.
Save taotetek/88cd49d0d3cd206ed26c to your computer and use it in GitHub Desktop.
package captainslog
import "sync"
type Queue struct {
q []SyslogMsg
lock *sync.Mutex
}
func NewQueue(max int) *Queue {
return &Queue{
lock: &sync.Mutex{},
q: make([]SyslogMsg, 0, max),
}
}
func (q *Queue) Enqueue(s SyslogMsg) {
q.lock.Lock()
defer q.lock.Unlock()
q.q = append(q.q, s)
}
func (q *Queue) Dequeue() SyslogMsg {
q.lock.Lock()
defer q.lock.Unlock()
m := q.q[0]
q.q = q.q[1:]
return m
}
func (q *Queue) Len() int {
return len(q.q)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment