diff options
author | Benji Dial <benji6283@gmail.com> | 2021-01-24 12:00:11 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-01-24 12:00:11 -0500 |
commit | bce944d1498eaa3b6940ee234c863b3548a66b37 (patch) | |
tree | ea40c087ab4f0f236aee8d158cf68550f5209f72 /src/user/knob/ipc.c | |
parent | ca731aa747214919df7b3dfe3478dbe787ce5b68 (diff) | |
download | portland-os-bce944d1498eaa3b6940ee234c863b3548a66b37.tar.gz |
graphics!
Diffstat (limited to 'src/user/knob/ipc.c')
-rw-r--r-- | src/user/knob/ipc.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/user/knob/ipc.c b/src/user/knob/ipc.c new file mode 100644 index 0000000..dbf1a22 --- /dev/null +++ b/src/user/knob/ipc.c @@ -0,0 +1,45 @@ +#include <pland/syscall.h> + +//blocking, returns early if other process is dead. +//return value is number of bytes written. +uint32_t try_send_ipc(_task_handle_t to, void *buffer, uint32_t size) { + const uint32_t size_backup = size; + while (size) { + uint32_t res = _ipc_send(to, size, buffer); + if (!res) { + _wait_ipc_read(to); + _yield_task(); + } + else if (res == -1) + return size_backup - size; + else { + size -= res; + buffer += res; + } + } +} + +//blocking, returns early if other process is dead. +//return value is number of bytes read. +uint32_t read_ipc(_task_handle_t from, void *buffer, uint32_t size) { + const uint32_t size_backup = size; + while (size) { + uint32_t res = _ipc_read(from, size, buffer); + if (!res) { + _wait_ipc_send(from); + _yield_task(); + } + else if (res == -1) + return size_backup - size; + else { + size -= res; + buffer += res; + } + } +} + +void flush_ipc(_task_handle_t from) { + uint8_t buf[4096]; + while (_ipc_read(from, 4096, buf)) + ; +}
\ No newline at end of file |