-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathstate.go
More file actions
55 lines (48 loc) · 1.76 KB
/
state.go
File metadata and controls
55 lines (48 loc) · 1.76 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
52
53
54
55
//go:build windows && !wcow
package plan9
// shareState represents the current state of a Plan9 share's lifecycle.
//
// The normal progression is:
//
// sharePending → shareAdded → shareRemoved
//
// If AddPlan9 fails, the owning goroutine moves the share to
// shareInvalid and records the error in [shareEntry.stateErr]. Other goroutines
// waiting on the same entry observe the invalid state and receive the original error.
// The entry is removed from the map immediately after the transition.
//
// Full state-transition table:
//
// Current State │ Trigger │ Next State
// ───────────────┼───────────────────────────┼─────────────────────────────
// sharePending │ AddPlan9 succeeds │ shareAdded
// sharePending │ AddPlan9 fails │ shareInvalid
// shareAdded │ RemovePlan9 succeeds │ shareRemoved
// shareRemoved │ (terminal — no transitions)│ —
// shareInvalid │ entry removed from map │ —
type shareState int
const (
// sharePending is the initial state; AddPlan9 has not yet completed.
sharePending shareState = iota
// shareAdded means AddPlan9 succeeded; the share is live on the VM.
shareAdded
// shareRemoved means RemovePlan9 succeeded. This is a terminal state.
shareRemoved
// shareInvalid means AddPlan9 failed.
shareInvalid
)
// String returns a human-readable name for the [shareState].
func (s shareState) String() string {
switch s {
case sharePending:
return "Pending"
case shareAdded:
return "Added"
case shareRemoved:
return "Removed"
case shareInvalid:
return "Invalid"
default:
return "Unknown"
}
}