From: arighi Date: Wed, 29 Sep 2010 12:50:16 +0000 (+0000) Subject: cpu: enforce a memory barrier inside cpu_relax() X-Git-Tag: 2.6.0~57 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=52c7785bca06ce9a837ac378662f351235ec10a7;p=bertos.git cpu: enforce a memory barrier inside cpu_relax() Put a memory barrier inside cpu_relax() to make sure the compiler doesn't cache variables used outside cpu_relax() in registers. Suppose to have the following case (used in many device drivers): static int done = false; void irq_handler(void) { done = true; } void wait_for_completion(void) { while (done == false) cpu_relax(); } If cpu_relax() is just considered a nop the compiler may decide to not reload the value in the variable "done" from memory, causing a neverending loop. The presence of an explicit memory barrier fixes this case. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4344 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/power.h b/bertos/cpu/power.h index 4e88def1..f161c698 100644 --- a/bertos/cpu/power.h +++ b/bertos/cpu/power.h @@ -68,6 +68,7 @@ */ INLINE void cpu_relax(void) { + MEMORY_BARRIER; #if CONFIG_KERN if (proc_preemptAllowed()) proc_yield();