summaryrefslogtreecommitdiffhomepage
path: root/pkg/flipcall/futex_linux.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-11-17 03:04:04 +0000
committergVisor bot <gvisor-bot@google.com>2020-11-17 03:04:04 +0000
commit893488fca8620a9de988a9f4d02c8117134b6253 (patch)
tree0b1615938c0b8d3cfaddaeef3c78cc092cf2cdf2 /pkg/flipcall/futex_linux.go
parentf7cb70e6045725c88bd0358af081a96c71764e2c (diff)
parent938aabeecb935771ab5be5eca5acff0bd19ebc97 (diff)
Merge release-20201109.0-54-g938aabeec (automated)
Diffstat (limited to 'pkg/flipcall/futex_linux.go')
-rw-r--r--pkg/flipcall/futex_linux.go50
1 files changed, 10 insertions, 40 deletions
diff --git a/pkg/flipcall/futex_linux.go b/pkg/flipcall/futex_linux.go
index 168c1ccff..0e559ee16 100644
--- a/pkg/flipcall/futex_linux.go
+++ b/pkg/flipcall/futex_linux.go
@@ -17,7 +17,6 @@
package flipcall
import (
- "encoding/json"
"fmt"
"runtime"
"sync/atomic"
@@ -26,55 +25,26 @@ import (
"gvisor.dev/gvisor/pkg/abi/linux"
)
-func (ep *Endpoint) futexConnect(req *ctrlHandshakeRequest) (ctrlHandshakeResponse, error) {
- var resp ctrlHandshakeResponse
-
- // Write the handshake request.
- w := ep.NewWriter()
- if err := json.NewEncoder(w).Encode(req); err != nil {
- return resp, fmt.Errorf("error writing handshake request: %v", err)
- }
- *ep.dataLen() = w.Len()
-
- // Exchange control with the server.
- if err := ep.futexSwitchToPeer(); err != nil {
- return resp, err
+func (ep *Endpoint) futexSetPeerActive() error {
+ if atomic.CompareAndSwapUint32(ep.connState(), ep.activeState, ep.inactiveState) {
+ return nil
}
- if err := ep.futexSwitchFromPeer(); err != nil {
- return resp, err
+ switch cs := atomic.LoadUint32(ep.connState()); cs {
+ case csShutdown:
+ return ShutdownError{}
+ default:
+ return fmt.Errorf("unexpected connection state before FUTEX_WAKE: %v", cs)
}
-
- // Read the handshake response.
- respLen := atomic.LoadUint32(ep.dataLen())
- if respLen > ep.dataCap {
- return resp, fmt.Errorf("invalid handshake response length %d (maximum %d)", respLen, ep.dataCap)
- }
- if err := json.NewDecoder(ep.NewReader(respLen)).Decode(&resp); err != nil {
- return resp, fmt.Errorf("error reading handshake response: %v", err)
- }
-
- return resp, nil
}
-func (ep *Endpoint) futexSwitchToPeer() error {
- // Update connection state to indicate that the peer should be active.
- if !atomic.CompareAndSwapUint32(ep.connState(), ep.activeState, ep.inactiveState) {
- switch cs := atomic.LoadUint32(ep.connState()); cs {
- case csShutdown:
- return ShutdownError{}
- default:
- return fmt.Errorf("unexpected connection state before FUTEX_WAKE: %v", cs)
- }
- }
-
- // Wake the peer's Endpoint.futexSwitchFromPeer().
+func (ep *Endpoint) futexWakePeer() error {
if err := ep.futexWakeConnState(1); err != nil {
return fmt.Errorf("failed to FUTEX_WAKE peer Endpoint: %v", err)
}
return nil
}
-func (ep *Endpoint) futexSwitchFromPeer() error {
+func (ep *Endpoint) futexWaitUntilActive() error {
for {
switch cs := atomic.LoadUint32(ep.connState()); cs {
case ep.activeState: