-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathtask_exit.go
More file actions
51 lines (43 loc) · 1.05 KB
/
Copy pathtask_exit.go
File metadata and controls
51 lines (43 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//go:build scheduler.tasks || scheduler.asyncify || scheduler.cores
package task
import "sync/atomic"
var (
mainTask *Task
liveTasks uint32
mainExitedByGoexit uint32
)
func addLiveTask(t *Task) {
if mainTask == nil {
mainTask = t
}
atomic.AddUint32(&liveTasks, 1)
}
// Goexit exits the current task because runtime.Goexit was called.
func Goexit() {
exit(true)
}
// Exit exits the current task after its entry function returns.
func Exit() {
exit(false)
}
func exit(goexit bool) {
t := Current()
if hasReleasableStack {
t.Exited = true
}
exitSynctest(t)
remaining := atomic.AddUint32(&liveTasks, ^uint32(0))
if t == mainTask {
if goexit {
if remaining == 0 {
runtimeFatal("all goroutines are asleep - deadlock!")
}
atomic.StoreUint32(&mainExitedByGoexit, 1)
}
} else if atomic.LoadUint32(&mainExitedByGoexit) != 0 && remaining == 0 {
runtimeFatal("all goroutines are asleep - deadlock!")
}
// TODO: explicitly free the stack after switching back to the scheduler.
Pause()
runtimeFatal("unreachable")
}