zephyr/samples/userspace/shared_mem/src/enc.h
Andy Ross 9e37e80a1d samples/userspace/shared_mem: Add volatile to interthread data
This test uses bare variables to synchronize state between threads,
but had forgotten volatile qualifiers on all the data.  So the
compiler was free to reorder and make assumptions that aren't valid
when the values are being written from other CPUs.

Single-cpu operation was fine because the code would always hit an
external function call like k_sleep() that would force it to re-read
from memory every time there was a context switch (timeslicing isn't
enabled on this test and the threads are cooperative), but on SMP the
volatiles can change at any time and we could see spurious state
mixups and hangs.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-02-03 09:31:56 -05:00

38 lines
681 B
C

/* enc.h */
/*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ENC_H
#define ENC_H
#include <sys/printk.h>
#define WHEEL_SIZE 26
#define IMOD(a, b) ((a + b) % WHEEL_SIZE)
#ifndef BYTE
#define BYTE unsigned char
#endif
void update_wheel_index(void);
char index_to_char(short i);
short char_to_index(char c);
int calc_rev_wheel(BYTE *wheel, BYTE *backpath);
char enig_enc(char pt);
extern volatile BYTE W1[26];
extern volatile BYTE W2[26];
extern volatile BYTE W3[26];
extern volatile BYTE R[26];
extern volatile BYTE W1R[26];
extern volatile BYTE W2R[26];
extern volatile BYTE W3R[26];
extern volatile int IW1;
extern volatile int IW2;
extern volatile int IW3;
#endif