Skip to content

Commit c8ffcb9

Browse files
author
Luca Toniolo
committed
hal_struct man page: add volatile to example, ignore generated .3 files
Mark shared blob pointers as volatile in the example code on both RT and userspace sides, with a note that volatile alone does not provide memory ordering guarantees and that atomics are needed for sequence-lock fields. Add hal_struct_attach/detach/newf.3 to docs/man/.gitignore so the asciidoc-generated man pages are not reported as untracked.
1 parent 6e54e8a commit c8ffcb9

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

docs/man/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ man3/hal_port_t.3
159159
man3/hal_port.3
160160
man3/hal_ready.3
161161
man3/hal_s32_t.3
162+
man3/hal_struct_attach.3
163+
man3/hal_struct_detach.3
164+
man3/hal_struct_newf.3
162165
man3/hal_set_constructor.3
163166
man3/hal_set_lock.3
164167
man3/hal_signal_delete.3

docs/src/man/man3/hal_struct_newf.3.adoc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ RT side (in _rtapi_app_main_):
7878

7979
----
8080
typedef struct { double value; int count; } my_params_t;
81-
static my_params_t *params;
81+
static volatile my_params_t *params;
8282
8383
my_params_t defaults = { 1.0, 0 };
8484
if (hal_struct_newf(comp_id, sizeof(*params), &defaults,
@@ -91,13 +91,20 @@ if (hal_struct_attach(prefix ".params", (void **)&params) < 0)
9191
Userspace side:
9292

9393
----
94-
my_params_t *params;
94+
volatile my_params_t *params;
9595
if (hal_struct_attach("mycomp.params", (void **)&params) < 0)
9696
return -1;
9797
/* read params->value, params->count ... */
9898
hal_struct_detach("mycomp.params");
9999
----
100100

101+
The pointer should be declared `volatile` on both sides so the compiler does
102+
not cache fields across accesses. Note that `volatile` alone does not
103+
guarantee memory ordering between threads or processes. For fields that must
104+
be read and written atomically (for example a sequence-lock head/tail pair),
105+
use C11 `_Atomic` or explicit `__atomic_*` intrinsics with an appropriate
106+
memory order.
107+
101108
== SEE ALSO
102109

103110
hal_init(3), hal_malloc(3), hal_exit(3), halcmd(1)

0 commit comments

Comments
 (0)