Page 1 of 1

Guards and Guarded

Posted: Fri Jun 06, 2014 12:58 pm
by Folknology
I have some questions about these attributes

Code: Select all

[[guarded]]
[[independent_guard]]
There is a brief mention of 'guarded' here but it doesn't provide a clearly documented example, I would like to understand all of the cases where this is required.

The 'independent_guard' was discovered when I added a state guard as part of a server task interface implementation like :

Code: Select all

select {
  ..
  case (state == READY) => display_if.refresh_display():
    refreshDisplay();
    break;
  ...
}
In this case because I had not added a guarded attribute to the refresh_display to definition of the display interface.

Code: Select all

../src/rgb-matrix-xcore.xc: In function `display_server':
../src/rgb-matrix-xcore.xc:73: error: select case on has guard without [[independent_guard]] case attribute or [[guarded]] interface function attribute
xmake[1]: *** [.build_Release/src/rgb-matrix-xcore.xc.o] Error 1
xmake: *** [bin/Release/rgb-matrix-xcore.xe] Error 2
This also makes me wonder why we need to add the Guard attribute, as the compiler clearly detects the requirement itself. Are there exceptions or corner cases where this isn't so? could an example be provided to explain these choices and best uses etc..

I would love for some light to be shone on these attributes and their correct use.

P.S. I rephrased and moved this question from the startkit thread as figured it was worthy of it's own.

regards
Al

Re: Guards and Guarded

Posted: Tue Jul 03, 2018 6:38 am
by gcore
I too would like to understand what [[independent_guard]] does. Could anyone from XMOS provide some documentation on the keyword and its intended use case?

Re: Guards and Guarded

Posted: Thu Jul 12, 2018 11:43 pm
by gcore
I’ve had an answer from XMOS.

The [[independent_guard]] attribute actually has no effect on the execution of the code, but allows the compiler to spot a potential situation where you have added a guarded statement when you don’t intend to. There is a recommendation that it is removed in future releases of the tools.