1/* 2 * Copyright 2017, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <camkes.h> 8#include <buffer.h> 9#include <string.h> 10#include <stdio.h> 11 12int run(void) { 13 14 char *buffer_str = (char*)buffer; 15 16 while (buffer_str[REVERSE_STRING_END_IDX] == 0) { 17 /* Poll the last byte of the buffer until the client is 18 * ready. This acquire is necessary to prevent the compiler 19 * from coalescing the reads and looping forever. */ 20 buffer_acquire(); 21 } 22 23 printf("Got string: %s\n", buffer_str); 24 25 int len = strnlen(buffer_str, REVERSE_STRING_MAX_LEN); 26 for (int i = 0; i < len / 2; ++i) { 27 int swap_idx = len - i - 1; 28 char tmp = buffer_str[i]; 29 buffer_str[i] = buffer_str[swap_idx]; 30 buffer_str[swap_idx] = tmp; 31 } 32 33 /* The following write to the buffer signals to the client 34 * that the server has finished reversing the string. This 35 * release is necessary to prevent the following write 36 * being re-ordered with the preceeding writes, which may 37 * otherwise happen as they are non-overlapping. */ 38 buffer_release(); 39 40 buffer_str[REVERSE_STRING_END_IDX] = 0; 41 42 return 0; 43} 44