From bc140c87dfd2f7f04b8f28019323f2bb3c334340 Mon Sep 17 00:00:00 2001 From: Andrew Martinez Date: Wed, 6 Mar 2024 10:04:58 -0500 Subject: [PATCH] reorganizes methods to be grouped by type --- common/event_cache.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/common/event_cache.go b/common/event_cache.go index ff9c9d0bc..c780911c6 100644 --- a/common/event_cache.go +++ b/common/event_cache.go @@ -88,22 +88,6 @@ func (cache *ForgetfulEventCache) ReplayFrom(_ uint64) ([]*edge_ctrl_pb.DataStat return nil, false } -func NewLoggingEventCache(logSize uint64) *LoggingEventCache { - return &LoggingEventCache{ - HeadLogIndex: 0, - LogSize: logSize, - Log: make([]uint64, logSize), - Events: map[uint64]*edge_ctrl_pb.DataState_Event{}, - } -} - -func (cache *LoggingEventCache) WhileLocked(callback func(uint64, bool)) { - cache.lock.Lock() - defer cache.lock.Unlock() - - callback(cache.currentIndex()) -} - func (cache *ForgetfulEventCache) CurrentIndex() (uint64, bool) { cache.lock.Lock() defer cache.lock.Unlock() @@ -128,6 +112,15 @@ type LoggingEventCache struct { Events map[uint64]*edge_ctrl_pb.DataState_Event } +func NewLoggingEventCache(logSize uint64) *LoggingEventCache { + return &LoggingEventCache{ + HeadLogIndex: 0, + LogSize: logSize, + Log: make([]uint64, logSize), + Events: map[uint64]*edge_ctrl_pb.DataState_Event{}, + } +} + func (cache *LoggingEventCache) SetCurrentIndex(index uint64) { cache.lock.Lock() defer cache.lock.Unlock() @@ -138,6 +131,13 @@ func (cache *LoggingEventCache) SetCurrentIndex(index uint64) { cache.Events = map[uint64]*edge_ctrl_pb.DataState_Event{} } +func (cache *LoggingEventCache) WhileLocked(callback func(uint64, bool)) { + cache.lock.Lock() + defer cache.lock.Unlock() + + callback(cache.currentIndex()) +} + func (cache *LoggingEventCache) Store(event *edge_ctrl_pb.DataState_Event, onSuccess OnStoreSuccess) error { cache.lock.Lock() defer cache.lock.Unlock()