Go源码问题

# 问题描述 - 在`sync/runtime.go`源码中存在下面样式的代码 ``` //line:37 // See runtime/sema.go for documentation. func runtime_notifyListAdd(l *notifyList) uint32 ``` - 在`runtime/sema.go`中可以找到notifyListAdd方法 ``` //line:476 // notifyListAdd adds the caller to a notify list such that it can receive // notifications. The caller must eventually call notifyListWait to wait for // such a notification, passing the returned ticket number. //go:linkname notifyListAdd sync.runtime_notifyListAdd func notifyListAdd(l *notifyList) uint32 { // This may be called concurrently, for example, when called from // sync.Cond.Wait while holding a RWMutex in read mode. return atomic.Xadd(&l.wait, 1) - 1 } ``` # 问题 1. runtime_notifyListAdd和notifyListAdd是怎么样建立起来关联的? 2. 我们在项目中怎么可以实现这样的写法?
已邀请:

lrita

赞同来自: 江小渔

* [Compiler Directives](https://golang.org/cmd/compile/#hdr-Compiler_Directives)
* 自己项目里照抄这种写法就行。比如[ratelimit.go](https://github.com/lrita/ratelimit/blob/master/ratelimit.go#L328-L329),而且package内得有任一`.s`后缀的文件,[stubs.s](https://github.com/lrita/ratelimit/blob/master/stubs.s)。

heramerom

赞同来自: 江小渔

//go:linkname notifyListAdd sync.runtime_notifyListAdd

要回复问题请先登录注册