samples/userspace/shared_mem: Fix SMP race
There was some unlocked initialization code in the "enc" thread that would race with the "pt" and "ct" threads if another CPU was available to run them (it was safe on UP because "enc" entered the queue first and was cooperative, the others wouldn't run until it blocked). Move it to main() and remove the enc_state guard variable which is no longer doing anything. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
4c2fc2aed7
commit
86ac7dc10a
1 changed files with 9 additions and 12 deletions
|
@ -78,7 +78,6 @@ struct k_thread ct_thread;
|
|||
K_THREAD_STACK_DEFINE(ct_stack, STACKSIZE);
|
||||
|
||||
_app_enc_d char encMSG[] = "ENC!\n";
|
||||
_app_enc_d int enc_state = 1;
|
||||
_app_enc_b char enc_pt[50]; /* Copy form shared pt */
|
||||
_app_enc_b char enc_ct[50]; /* Copy to shared ct */
|
||||
|
||||
|
@ -104,6 +103,15 @@ void main(void)
|
|||
struct k_mem_partition *dom0_parts[] = {&part0, &part1};
|
||||
k_tid_t tPT, tENC, tCT;
|
||||
|
||||
fBUFIN = 0; /* clear flags */
|
||||
fBUFOUT = 0;
|
||||
calc_rev_wheel((BYTE *) &W1, (BYTE *)&W1R);
|
||||
calc_rev_wheel((BYTE *) &W2, (BYTE *)&W2R);
|
||||
calc_rev_wheel((BYTE *) &W3, (BYTE *)&W3R);
|
||||
IW1 = 0;
|
||||
IW2 = 0;
|
||||
IW3 = 0;
|
||||
|
||||
k_thread_access_grant(k_current_get(), &allforone);
|
||||
|
||||
/*
|
||||
|
@ -169,17 +177,6 @@ void enc(void)
|
|||
{
|
||||
|
||||
int index, index_out;
|
||||
if (enc_state == 1) {
|
||||
fBUFIN = 0; /* clear flags */
|
||||
fBUFOUT = 0;
|
||||
calc_rev_wheel((BYTE *) &W1, (BYTE *)&W1R);
|
||||
calc_rev_wheel((BYTE *) &W2, (BYTE *)&W2R);
|
||||
calc_rev_wheel((BYTE *) &W3, (BYTE *)&W3R);
|
||||
IW1 = 0;
|
||||
IW2 = 0;
|
||||
IW3 = 0;
|
||||
enc_state = 0;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
k_sem_take(&allforone, K_FOREVER);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue