Blocking receive a message 1. Empty -> Receiving, return (None, None) 2. Sending -> Empty, return (receiving thread, sending thread) 3. Receiving -> return (receiving thread, None) Error returned to thread 4. SendReceiving -> Receiving, return (receiving thread, None) Returns ------- Zero, one or two threads (thread1, thread2) thread1 should be started asap thread2 should be scheduled
(&mut self, thread: Box<Thread>)
| 103 | /// thread1 should be started asap |
| 104 | /// thread2 should be scheduled |
| 105 | pub fn receive(&mut self, thread: Box<Thread>) |
| 106 | -> (Option<Box<Thread>>, Option<Box<Thread>>) { |
| 107 | match &*self { |
| 108 | Rendezvous::Empty => { |
| 109 | // Can receive from any thread |
| 110 | *self = Rendezvous::Receiving(thread, None); |
| 111 | (None, None) |
| 112 | } |
| 113 | Rendezvous::Sending(_, _) => { |
| 114 | // Complete the message transfer |
| 115 | if let Rendezvous::Sending(snd_thread, message) = mem::replace(self, Rendezvous::Empty) { |
| 116 | thread.return_message(message); |
| 117 | if let Some(ref t) = snd_thread { |
| 118 | t.return_error(0); // Success |
| 119 | } |
| 120 | return (Some(thread), snd_thread); |
| 121 | } |
| 122 | (None, None) // This should never be reached |
| 123 | } |
| 124 | Rendezvous::Receiving(_, _) => { |
| 125 | // Already receiving |
| 126 | thread.return_error(syscalls::SYSCALL_ERROR_RECV_BLOCKING); |
| 127 | (Some(thread), None) |
| 128 | } |
| 129 | Rendezvous::SendReceiving(_, _) => { |
| 130 | // Sending, expecting a reply from the same thread |
| 131 | if let Rendezvous::SendReceiving(snd_thread, message) = mem::replace(self, Rendezvous::Empty) { |
| 132 | thread.return_message(message); |
| 133 | // Wait for a reply from the receiving thread |
| 134 | *self = Rendezvous::Receiving(snd_thread, Some(thread.tid())); |
| 135 | return (Some(thread), None); |
| 136 | } |
| 137 | (None, None) |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | /// Send a message and block on receive from the same thread |
| 143 | /// |
no test coverage detected