Skip to content

hal: Make HAL mutex recursive and use acquire/release functions#4259

Merged
grandixximo merged 1 commit into
LinuxCNC:masterfrom
BsAtHome:halgs_recursive-mutex
Jul 22, 2026
Merged

hal: Make HAL mutex recursive and use acquire/release functions#4259
grandixximo merged 1 commit into
LinuxCNC:masterfrom
BsAtHome:halgs_recursive-mutex

Conversation

@BsAtHome

@BsAtHome BsAtHome commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Change the HAL mutex from a simple mutex to a recursive mutex. This is necessary to support coming changes in the HAL API.

Many changes in the PR are simply to replace the old mutex get/give with a halpr_mutex_acquire/halpr_mutex_release call. This is actually a hal_lib private API, but removing access to hal_priv.h would require a huge change-set. This way it will be done gradually.
The forced mutex release function (used in halcmd) is now part of hal_lib so that the caller no longer needs to access library internals. Anyway, when you need to force-release the mutex, then all bets are off and you should restart anyway.

The rtapi_app is now cleared of accessing the HAL private API. The newinst code (if anybody is using it) now uses a call into a specially published hal_lib function to call the constructor instead of extracting a halpr_xxx function.
The has been postponed because it changes a prototype that may give a problem. However, it is unlikely that anyone is using constructable components since this is (already since 2.2) an experimental feature.

@BsAtHome
BsAtHome requested a review from grandixximo July 22, 2026 09:40

@grandixximo grandixximo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, at src/hal/utils/halcompile.g:549:

The typedef gained const, but halcompile still emits static int export_1(char *prefix, char *argstr). Out-of-tree constructable comps will warn (C) or fail (C++) against the new header. Suggest emitting const char * here and at the registration site (line 679 is fine as-is).

Should it be fixed here, or keeping that for later?

Comment thread src/hal/utils/halcmd_commands.cc
Comment thread src/hal/hal_lib.c Outdated
Comment thread src/hal/hal.h Outdated
@BsAtHome
BsAtHome force-pushed the halgs_recursive-mutex branch from f99b94d to b65b5d0 Compare July 22, 2026 11:33
@BsAtHome
BsAtHome force-pushed the halgs_recursive-mutex branch from b65b5d0 to 07ca160 Compare July 22, 2026 11:40
@BsAtHome

Copy link
Copy Markdown
Contributor Author

The typedef gained const, but halcompile still emits static int export_1(char *prefix, char *argstr). Out-of-tree constructable comps will warn (C) or fail (C++) against the new header. Suggest emitting const char * here and at the registration site (line 679 is fine as-is).

Should it be fixed here, or keeping that for later?

This is a such a damned if you do, damned if you don't case... The whole constructable component stuff has been experimental for ages and I have never seen an instance where it is used. No in-tree component uses it and wonder if out-of-tree knows it exists. Changing it risks breaking stuff that is a fringe use from the past. Leaving it as is means some things can not be properly isolated.

The constructable option is not documented in halcompile and the newinst command in halcmd cannot process it (it is embedded i a #if 0). Only rtapi_app knows about it.

Probably need to ask on the dev-list if this is used by anybody.

@grandixximo

Copy link
Copy Markdown
Contributor

Ok, are you sending an email up to the ML?
On hold till we get a reply? Or merge as is since I think you are not touching it now if I'm not wrong...

@BsAtHome

BsAtHome commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Ok, are you sending an email up to the ML?

Yes, just writing it.

On hold till we get a reply? Or merge as is since I think you are not touching it now if I'm not wrong...

I took it out so this can get merged without further delay. The constructable/newinst stuff is not paramount to the progression. Just added a FIXME so it gets cleaned up later.

@grandixximo
grandixximo merged commit 291070f into LinuxCNC:master Jul 22, 2026
16 checks passed
@grandixximo

grandixximo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Only found one real user on github gwassem/linuxcnc_sim , but his code is broken, I think based on machinekit (where newinst actually works and is used) posted an issue there about it.
After having done a quick search of newinst and since I found it used only once, I doubt we'll get anything back from the mailing list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants