-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfifo.go
More file actions
46 lines (38 loc) · 663 Bytes
/
fifo.go
File metadata and controls
46 lines (38 loc) · 663 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package queue
// FIFO engine implementation.
type fifo struct {
c chan item
}
func (e *fifo) init(config *Config) error {
e.c = make(chan item, config.Capacity)
return nil
}
func (e *fifo) enqueue(itm *item, block bool) bool {
if !block {
select {
case e.c <- *itm:
return true
default:
return false
}
}
e.c <- *itm
return true
}
func (e *fifo) dequeue() (item, bool) {
itm, ok := <-e.c
return itm, ok
}
func (e *fifo) dequeueSQ(_ uint32) (item, bool) {
return e.dequeue()
}
func (e *fifo) size() int {
return len(e.c)
}
func (e *fifo) cap() int {
return cap(e.c)
}
func (e *fifo) close(_ bool) error {
close(e.c)
return nil
}