Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Fixed deadlock.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kugelschieber committed Feb 4, 2017
1 parent 9096adf commit 98a4873
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

**1.2.2**

* bugfix: deadlock on compiling multile files at once

**1.2.1**

* bugfix: new line after while for pretty printing
Expand Down
24 changes: 6 additions & 18 deletions src/main/asl.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

const (
version = "1.2.1"
version = "1.2.2"
extension = ".asl"
sqfextension = ".sqf"
typeinfo = "types"
Expand Down Expand Up @@ -104,17 +104,15 @@ func readAslFiles(path string) {
}

// Recovers and prints thrown error.
func recoverCompileError(file string, waiter chan bool) {
func recoverCompileError(file string) {
if r := recover(); r != nil {
fmt.Println("Compile error in file "+file+":", r)
}

waiter <- true // the show must go on
}

// Compiles a single ASL file.
func compileFile(path string, file ASLFile, waiter chan bool) {
defer recoverCompileError(file.in, waiter)
func compileFile(path string, file ASLFile) {
defer recoverCompileError(file.in)

// read file
out := filepath.FromSlash(path + PathSeparator + file.out + PathSeparator + file.newname + sqfextension)
Expand All @@ -138,22 +136,12 @@ func compileFile(path string, file ASLFile, waiter chan bool) {
fmt.Println("Error writing file: " + file.out)
fmt.Println(err)
}

waiter <- true // done
}

// Compiles ASL files concurrently.
// Compiles ASL files.
func compile(path string) {
waiter := make(chan bool, len(aslFiles))

// fire compile
for i := 0; i < len(aslFiles); i++ {
go compileFile(path, aslFiles[i], waiter)
}

// wait until all files are compiled
for i := 0; i < len(aslFiles); i++ {
<-waiter
compileFile(path, aslFiles[i])
}
}

Expand Down

0 comments on commit 98a4873

Please sign in to comment.