gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sync/locking/locking.bzl (about) 1 """Mutex-s rules.""" 2 3 load("//tools/go_generics:defs.bzl", "go_template_instance") 4 5 def _substrs(nested_lock_names): 6 substrs = {"genericMark": "prefix"} 7 if nested_lock_names == None or len(nested_lock_names) == 0: 8 return substrs 9 quoted_names = ["\"%s\"" % (n,) for n in nested_lock_names] 10 constant_names = ["Lock%s = lockNameIndex(%d)" % (n.title(), idx) for idx, n in enumerate(nested_lock_names)] 11 substrs["func initLockNames() {}"] = "func initLockNames() { lockNames = []string{%s} }" % (", ".join(quoted_names),) 12 substrs["/" + "/ LOCK_NAME_INDEX_CONSTANTS"] = "const (\n\t%s\n)" % ("\n\t".join(constant_names),) 13 return substrs 14 15 def declare_mutex(package, name, out, prefix, nested_lock_names = None): 16 go_template_instance( 17 name = name, 18 out = out, 19 package = package, 20 prefix = prefix, 21 input_substrs = _substrs(nested_lock_names = nested_lock_names), 22 template = "//pkg/sync/locking:generic_mutex", 23 ) 24 25 def declare_rwmutex(package, name, out, prefix, nested_lock_names = None): 26 go_template_instance( 27 name = name, 28 out = out, 29 package = package, 30 prefix = prefix, 31 input_substrs = _substrs(nested_lock_names = nested_lock_names), 32 template = "//pkg/sync/locking:generic_rwmutex", 33 )