summaryrefslogtreecommitdiffstats
path: root/src/core.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-08-16 03:24:23 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-08-16 03:33:48 +0900
commit487c8fe88f4cfcc55850b8aef73665b1d09b8fe0 (patch)
treed21e3b4a4fdcb2a6d6980d1f47fb3ede5bd5c557 /src/core.go
parent0d171ba1d81886c6f9caf61867129e6daa268cd6 (diff)
Make Reader event notification asynchronous
Instead of notifying the event coordinator (EventBox) whenever a new line is arrived, start a background goroutine that periodically does the task. Atomic.StoreInt32 is much cheaper than mutex synchronization that happens during EventBox update.
Diffstat (limited to 'src/core.go')
-rw-r--r--src/core.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/core.go b/src/core.go
index 968d407b..61f14f91 100644
--- a/src/core.go
+++ b/src/core.go
@@ -115,9 +115,9 @@ func Run(opts *Options, revision string) {
// Reader
streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync
if !streamingFilter {
- reader := Reader{func(data []byte) bool {
+ reader := NewReader(func(data []byte) bool {
return chunkList.Push(data)
- }, eventBox, opts.ReadZero}
+ }, eventBox, opts.ReadZero)
go reader.ReadSource()
}
@@ -150,7 +150,7 @@ func Run(opts *Options, revision string) {
found := false
if streamingFilter {
slab := util.MakeSlab(slab16Size, slab32Size)
- reader := Reader{
+ reader := NewReader(
func(runes []byte) bool {
item := Item{}
if chunkList.trans(&item, runes, 0) {
@@ -160,7 +160,7 @@ func Run(opts *Options, revision string) {
}
}
return false
- }, eventBox, opts.ReadZero}
+ }, eventBox, opts.ReadZero)
reader.ReadSource()
} else {
eventBox.Unwatch(EvtReadNew)