/
hbtso.go
39 lines (30 loc) · 1 KB
/
hbtso.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// HBTSO is an HBGenerator that implements TSO.
type HBTSO struct{}
func (HBTSO) HappensBefore(p *Prog, i, j PC) HBType {
op1, op2 := p.OpAt(i), p.OpAt(j)
sameThread := i.TID == j.TID
switch {
case op1.Type == OpStore && op2.Type == OpStore:
// Stores are totally ordered.
return HBHappensBefore
case sameThread && op1.Type == OpLoad && op2.Type == OpLoad:
// Loads are program ordered.
return HBHappensBefore
case sameThread && op1.Type == OpLoad && op2.Type == OpStore:
// Loads are program ordered before stores. (But *not*
// the other way around.)
return HBHappensBefore
case op1.Type == OpStore && op2.Type == OpLoad && op1.Var == op2.Var:
// If the load observes the store, then the store
// happened before the load.
return HBConditional
}
return HBConcurrent
}
func (HBTSO) String() string {
return "TSO"
}