Skip to content

Commit

Permalink
Fix bug with atomic for 32 bit architectures
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Mar 4, 2020
1 parent 6bf1d84 commit f791660
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type RouteGroup struct {
desc routing.RouteDescriptor // describes the route group
rt routing.Table

lastSent int64

// 'tps' is transports used for writing/forward rules.
// It should have the same number of elements as 'fwd'
// where each element corresponds with the adjacent element in 'fwd'.
Expand All @@ -79,15 +81,12 @@ type RouteGroup struct {
fwd []routing.Rule // forward rules (for writing)
rvs []routing.Rule // reverse rules (for reading)

lastSent int64

// 'readCh' reads in incoming packets of this route group.
// - Router should serve call '(*transport.Manager).ReadPacket' in a loop,
// and push to the appropriate '(RouteGroup).readCh'.
readCh chan []byte // push reads from Router
readChMu sync.Mutex
readBuf bytes.Buffer // for read overflow
once sync.Once

readDeadline deadline.PipeDeadline
writeDeadline deadline.PipeDeadline
Expand All @@ -99,6 +98,7 @@ type RouteGroup struct {
closed chan struct{}
// used to wait for all the `Close` packets to run through the loop and come back
closeDone sync.WaitGroup
once sync.Once
}

// NewRouteGroup creates a new RouteGroup.
Expand Down
7 changes: 7 additions & 0 deletions pkg/router/route_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ func TestNewRouteGroup(t *testing.T) {
require.Equal(t, DefaultRouteGroupConfig(), rg.cfg)
}

// Uncomment for debugging
/*
func TestRouteGroupAlignment(t *testing.T) {
alignment.PrintStruct(RouteGroup{})
}
*/

func TestRouteGroup_Close(t *testing.T) {
rg1, rg2, m1, m2, teardown := setupEnv(t)

Expand Down
20 changes: 20 additions & 0 deletions pkg/util/alignment/alignment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package alignment

import (
"fmt"
"reflect"
)

// PrintStruct prints detailed information of struct fields alignment.
func PrintStruct(v interface{}) {
typ := reflect.TypeOf(v)
fmt.Printf("Struct is %d bytes long\n", typ.Size())
// We can run through the fields in the structure in order
n := typ.NumField()
for i := 0; i < n; i++ {
field := typ.Field(i)
fmt.Printf("%s at offset %v, size=%d, align=%d\n",
field.Name, field.Offset, field.Type.Size(),
field.Type.Align())
}
}

0 comments on commit f791660

Please sign in to comment.