type m struct {
/*
1. 所有調用棧的Goroutine,這是一個比較特殊的Goroutine。
2. 普通的Goroutine棧是在Heap分配的可增長的stack,而g0的stack是M對應的線程棧。
3. 所有與調度相關的代碼,都會先切換到g0的棧再執行。
*/
g0 *g // goroutine with scheduling stack
morebuf gobuf // gobuf arg to morestack
divmod uint32 // div/mod denominator for arm - known to liblink
// Fields not known to debuggers.
procid uint64 // for debuggers, but offset not hard-coded
gsignal *g // signal-handling g
goSigStack gsignalStack // Go-allocated signal handling stack
sigmask sigset // storage for saved signal mask
tls [6]uintptr // thread-local storage (for x86 extern register)
// 表示M的起始函數。其實就是我們 go 語句攜帶的那個函數。
mstartfn func()
// M中當前運行的goroutine
curg *g // current running goroutine
caughtsig guintptr // goroutine running during fatal signal
// 與M綁定的P,如果爲nil表示空閒
p puintptr // attached p for executing go code (nil if not executing go code)
// 用於暫存於當前M有潛在關聯的P。 (預聯)當M重新啓動時,即用預聯的這個P做關聯啦
nextp puintptr
id int64
mallocing int32
throwing int32
// 當前m是否關閉搶佔式調度
preemptoff string // if != "", keep curg running on this m
/** */
locks int32
dying int32
profilehz int32
// 不爲0表示此m在做幫忙gc。helpgc等於n只是一個編號
helpgc int32
// 自旋狀態,表示當前M是否正在自旋尋找G。在尋找過程中M處於自旋狀態。
spinning bool // m is out of work and is actively looking for work
blocked bool // m is blocked on a note
inwb bool // m is executing a write barrier
newSigstack bool // minit on C thread called sigaltstack
printlock int8
incgo bool // m is executing a cgo call
freeWait uint32 // if == 0, safe to free g0 and delete m (atomic)
fastrand [2]uint32
needextram bool
traceback uint8
ncgocall uint64 // number of cgo calls in total
ncgo int32 // number of cgo calls currently in progress
cgoCallersUse uint32 // if non-zero, cgoCallers in use temporarily
cgoCallers *cgoCallers // cgo traceback if crashing in cgo call
park note
//這個域用於鏈接allm
alllink *m // on allm
schedlink muintptr
mcache *mcache
// 表示與當前M鎖定的那個G。運行時系統會把 一個M 和一個G鎖定,一旦鎖定就只能雙方相互作用,不接受第三者。
lockedg guintptr
createstack [32]uintptr // stack that created this thread.
lockedExt uint32 // tracking for external LockOSThread
lockedInt uint32 // tracking for internal lockOSThread
nextwaitm muintptr // next m waiting for lock
waitunlockf unsafe.Pointer // todo go func(*g, unsafe.pointer) bool
waitlock unsafe.Pointer
waittraceev byte
waittraceskip int
startingtrace bool
syscalltick uint32
thread uintptr // thread handle
freelink *m // on sched.freem
// these are here because they are too large to be on the stack
// of low-level NOSPLIT functions.
libcall libcall
libcallpc uintptr // for cpu profiler
libcallsp uintptr
libcallg guintptr
syscall libcall // stores syscall parameters on windows
vdsoSP uintptr // SP for traceback while in VDSO call (0 if not in call)
vdsoPC uintptr // PC for traceback while in VDSO call
mOS
}
golang源碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.