Skip to content

Commit

Permalink
Merge pull request #3 from elopio/mutex
Browse files Browse the repository at this point in the history
Added a mutex to the writer.
  • Loading branch information
come-maiz committed Jan 4, 2016
2 parents 00b2585 + f3b399a commit 30fcecc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion subunit.go
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"hash/crc32"
"io"
"sync"
"time"
)

Expand Down Expand Up @@ -66,6 +67,7 @@ var status = map[string]byte{
"fail": 0x6,
"xfail": 0x7,
}
var m sync.Mutex

func makeLen(baseLen int) (length int, err error) {
length = baseLen + 4 // Add the length of the CRC32.
Expand Down Expand Up @@ -151,7 +153,8 @@ func (e *Event) write(writer io.Writer) error {
// Add the CRC32
crc := crc32.ChecksumIEEE(b.Bytes())
binary.Write(&b, binary.BigEndian, crc)

m.Lock()
defer m.Unlock()
_, err = writer.Write(b.Bytes())
return err
}
Expand Down

0 comments on commit 30fcecc

Please sign in to comment.