Guards and Guarded

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Guards and Guarded

Post 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


gcore
Member
Posts: 11
Joined: Thu Oct 06, 2016 4:58 am

Post 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?
gcore
Member
Posts: 11
Joined: Thu Oct 06, 2016 4:58 am

Post 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.
Post Reply