Skip to content
This repository has been archived by the owner on Dec 3, 2019. It is now read-only.

Commit

Permalink
remove lock
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranrg committed Jun 16, 2017
1 parent a1bec6b commit 735c9f4
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions client/cherami/outputhostconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type (
logger bark.Logger
reporter metrics.Reporter

lk sync.Mutex
opened int32
closed int32
wg sync.WaitGroup
Expand Down Expand Up @@ -109,10 +108,8 @@ func newOutputHostConnection(ackClient cherami.TChanBOut, wsConnector WSConnecto
}

func (conn *outputHostConnection) open() error {
conn.lk.Lock()
defer conn.lk.Unlock()

if atomic.LoadInt32(&conn.opened) == 0 {
if atomic.CompareAndSwapInt32(&conn.opened, 0, 1) {
switch conn.protocol {
case cherami.Protocol_WS:
conn.logger.Infof("Using websocket to connect to output host %s", conn.connKey)
Expand Down Expand Up @@ -145,16 +142,13 @@ func (conn *outputHostConnection) open() error {
conn.wg.Add(1)
go conn.writeAcksPump()

atomic.StoreInt32(&conn.opened, 1)
conn.logger.Info("Output host connection opened.")
}

return nil
}

func (conn *outputHostConnection) close() {
conn.lk.Lock()
defer conn.lk.Unlock()

if atomic.CompareAndSwapInt32(&conn.closed, 0, 1) {
select {
Expand All @@ -165,7 +159,8 @@ func (conn *outputHostConnection) close() {

close(conn.closeChannel)
conn.closeAcksBatchCh() // necessary to shutdown writeAcksPump within the connection
conn.wg.Wait() // wait for the goroutines to finish up

conn.wg.Wait() // wait for the goroutines to finish up
conn.logger.Info("Output host connection closed.")
}
}
Expand Down

0 comments on commit 735c9f4

Please sign in to comment.