Skip to content
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: 3 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ func GetStatistics(path string) (statistics Statistics, err error) {
}

var waitGroup sync.WaitGroup
var mutex sync.Mutex


waitGroup.Add(1)
tree.Chdir(path) //nolint:errcheck
goAroundCalculating(&waitGroup, &mutex, tree, list, &statistics, componentsSet)
goAroundCalculating(&waitGroup, tree, list, &statistics, componentsSet)
tree.Chdir("..") //nolint:errcheck
waitGroup.Wait()

Expand All @@ -65,7 +64,6 @@ func GetStatistics(path string) (statistics Statistics, err error) {

func goAroundCalculating(
waitGroup *sync.WaitGroup,
mutex *sync.Mutex,
tree t.Tree,
list t.Nodes,
statistics *Statistics,
Expand All @@ -85,7 +83,7 @@ func goAroundCalculating(

waitGroup.Add(1)
tree.Chdir(node.Name) //nolint:errcheck
go goAroundCalculating(waitGroup, mutex, tree.Copy(), newList, statistics, componentsSet.Copy())
go goAroundCalculating(waitGroup, tree.Copy(), newList, statistics, componentsSet.Copy())
tree.Chdir("..") //nolint:errcheck

if exists {
Expand All @@ -98,7 +96,6 @@ func goAroundCalculating(
LOC := uint64(1)
tree.ReadNodeLineByLine(node.Name, proceedLine, &LOC)

mutex.Lock()
statistics.Total.Append(LOC, 1)
statistics.Languages[language].Append(LOC, 1)

Expand All @@ -111,7 +108,6 @@ func goAroundCalculating(
for componentTitle := range componentsSet.Elements {
statistics.Components[componentTitle].Append(LOC, 1)
}
mutex.Unlock()
}
}
}
Expand All @@ -120,7 +116,7 @@ func goAroundCalculating(
func initItems(mapping map[string]string) (items Items) {
items = make(Items)
for _, value := range mapping {
items[value] = &TableItem{Files: 0, LOC: 0}
items[value] = &TableItem{Files: 0, LOC: 0, mutex: sync.Mutex{}}
}
return
}
Expand Down
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package statloc

import "sync"

type (
component struct {
Title string
Expand All @@ -14,6 +16,7 @@ type (
TableItem struct {
LOC uint64
Files uint64
mutex sync.Mutex
}

Items map[string]*TableItem
Expand Down Expand Up @@ -62,6 +65,8 @@ func (c *component) Copy(elements map[string]struct{}) *component {
}

func (t *TableItem) Append(LOC uint64, files uint64) {
t.mutex.Lock()
t.LOC += LOC
t.Files += files
t.mutex.Unlock()
}
Loading