github.com/aclements/go-misc@v0.0.0-20240129233631-2f6ede80790c/memmodel/hbacqrel.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 // HBAcqRel is an HBGenerator that implements acquire/release. 8 type HBAcqRel struct{} 9 10 func (HBAcqRel) HappensBefore(p *Prog, i, j PC) HBType { 11 op1, op2 := p.OpAt(i), p.OpAt(j) 12 //sameThread := i.TID == j.TID 13 14 // TODO: Is this right? 15 16 switch { 17 case op1.Type == OpStore && op2.Type == OpStore && op1.Var == op2.Var: 18 // Stores to the same location are totally ordered. 19 return HBHappensBefore 20 21 // case sameThread && op1.Type == OpSyncLoad && (op2.Type == OpSyncLoad || op2.Type == OpRegLoad): 22 // // Loads are not allowed to move above a sync load. 23 // return HBHappensBefore 24 25 // case sameThread && (op1.Type == OpSyncStore || op1.Type == OpRegStore) && op2.Type == OpSyncStore: 26 // // Stores are not allowed to move below a sync store. 27 // return HBHappensBefore 28 29 case op1.Type == OpStore && op2.Type == OpLoad && op1.Var == op2.Var: 30 // If the load observes the store, then the store 31 // happened before the load. 32 return HBConditional 33 } 34 35 return HBConcurrent 36 } 37 38 func (HBAcqRel) String() string { 39 return "AcqRel" 40 }