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

赞同来自: 江小渔

heramerom

赞同来自: 江小渔

//go:linkname notifyListAdd sync.runtime_notifyListAdd

要回复问题请先登录注册