Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Loop Handling #24

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion bin/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ func LZRMain() {
var intervalLoop = options.Timeout*lzr.NumHandshakes()*2
go func() {
for {
time.Sleep(time.Duration(intervalLoop)*time.Second)
startTime := time.Now()
for time.Since(startTime) < time.Duration(intervalLoop)*time.Second {
if (ipMeta.HasUpdates()) {
startTime = time.Now()
ipMeta.ResetUpdates()
continue
}
time.Sleep(time.Duration(intervalLoop)*time.Millisecond)
}
if (ipMetaSize == ipMeta.Count()) {
fmt.Fprintln(os.Stderr,"Infinite Loop, Breaking.")
infiniteLoop = true
Expand Down
26 changes: 26 additions & 0 deletions concurrentMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type pState []*pStateShared
type pStateShared struct {
items map[string]*packet_state
sync.RWMutex // Read Write mutex, guards access to internal map.
updated bool
}

// Creates a new concurrent map.
Expand All @@ -61,6 +62,7 @@ func (m pState) Insert(key string, p * packet_state) {
shard.Lock()

shard.items[key] = p
shard.updated = true
shard.Unlock()
}

Expand Down Expand Up @@ -112,9 +114,33 @@ func (m pState) Remove(key string) {
shard := m.GetShard(key)
shard.Lock()
delete(shard.items, key)
shard.updated = true
shard.Unlock()
}

// HasUpdates checks if map has been updated
func (m pState) HasUpdates() bool {
for i := 0; i < SHARD_COUNT; i++ {
shard := m[i]
shard.RLock()
if shard.updated {
shard.RUnlock()
return true
}
shard.RUnlock()
}
return false
}

// ResetUpdates resets all updates to false
func (m pState) ResetUpdates() {
for i := 0; i < SHARD_COUNT; i++ {
shard := m[i]
shard.Lock()
shard.updated = false
shard.Unlock()
}
}

/* FOR PACKET_METADATA */
//is Processing for goPackets
Expand Down
Loading