Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core (largely doc): Differentiate message types from thread flags #17472

Merged
merged 4 commits into from
Feb 27, 2022

Conversation

chrysn
Copy link
Member

@chrysn chrysn commented Jan 5, 2022

Contribution description

How to make sure own thread flags or message types do not conflict with preexisting ones (especially with the lack of a comprehensive of predefined ones for the latter) is difficult from the current documentation; this change set:

  • clarifies that flags will be set by the OS without solicitation,
    • and adds a single define against which custom use can be checked; and
  • states that messages are not set by the OS willy-nilly, and that system-wide uniqueness of numbers is not really necessary (but just a good practice by the standard library)

(and fixes an obsolete number in the process).

Testing procedure

  • Agree with the changes to the docs
  • Watch nothing break in the tests from an added define

Issues/PRs references

This contains clean-up from #7717

This has been wrong since 317b013 when a third predefined flag was
removed.
@chrysn chrysn added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: doc Area: Documentation Area: core Area: RIOT kernel. Handle PRs marked with this with care! CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs >1 ACK Integration Process: This PR requires more than one ACK labels Jan 5, 2022
@chrysn chrysn requested a review from kaspar030 as a code owner January 5, 2022 18:46
@github-actions github-actions bot removed the Area: doc Area: Documentation label Jan 5, 2022
*
* This bit mask is set for all thread flag bits that are predefined in RIOT.
* Flags within this set may be set on a thread by the operating system without
* thre thread soliciting them (though not all are; for example, @ref
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* thre thread soliciting them (though not all are; for example, @ref
* the thread soliciting them (though not all are; for example, @ref

* When using custom flags, asserting that they are not in this set can help
* avoid conflict with future additions to the predefined flags.
*/
#define THREAD_FLAG_PREDEFINED THREAD_FLAG_MSG_WAITING | THREAD_FLAG_TIMEOUT
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#define THREAD_FLAG_PREDEFINED THREAD_FLAG_MSG_WAITING | THREAD_FLAG_TIMEOUT
#define THREAD_FLAG_PREDEFINED (THREAD_FLAG_MSG_WAITING | THREAD_FLAG_TIMEOUT)

@@ -98,6 +101,20 @@ extern "C" {
* @see xtimer_set_timeout_flag
*/
#define THREAD_FLAG_TIMEOUT (1u << 14)


Copy link
Contributor

Choose a reason for hiding this comment

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

extra newline

Copy link
Member Author

Choose a reason for hiding this comment

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

That was originally intentional to set it off from the others -- revisiting it, given the others don't have newlines between them, added.

* GNRC_NETAPI_MSG_TYPE_RCV & co are defined. These are fixed in the sense that
* registering for a particular set of messages (for the above, e.g. @ref
* gnrc_netreg_register) will use these message types. Threads that do nothing
* to receive such messages need not worry can safely use the same numbers for
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* to receive such messages need not worry can safely use the same numbers for
* to receive such messages need can safely use the same numbers for

@kaspar030
Copy link
Contributor

LGTM, nice clarifications. Only the "may be considered an error", maybe needs some addition, or remove it? What do you think?

@chrysn
Copy link
Member Author

chrysn commented Jan 5, 2022

All applied, including an addition on best practice to log. (Although I think I'm more on the side of "log with extreme prejudice").

I'd advocate declaring this clearly as an error (not merely "usage error") not for the behavior when receiving an unexpected message, but for how it can go wrong worse: Whichever component sends a thread messages that the recipient does not expect might also hit a message type the recipient does expect, and then the recipient might free what's behind that pointer (if the semantics are similar to what is done in GNRC), and generally we're in deep UB and potential-security-issue land there. (Say the sender thinks of the message as a pointer to some user input buffer, but the recipient thinks of it as a struct and calls through a pointer in there...)

@chrysn chrysn removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jan 5, 2022
@chrysn
Copy link
Member Author

chrysn commented Jan 5, 2022

(CI-ready flag cleared as nothing showed up in 1/2h of running, and it'll be run again after squashing anyway).

@chrysn
Copy link
Member Author

chrysn commented Jan 12, 2022

Can I squash this?

@fjmolinas
Copy link
Contributor

@kaspar030 is this Ok to squash?

@benpicco
Copy link
Contributor

Please squash!

@chrysn chrysn added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 26, 2022
Co-authored-by: benpicco <benpicco@googlemail.com>
Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

ACK.

@chrysn chrysn added the Area: doc Area: Documentation label Feb 27, 2022
@kaspar030 kaspar030 merged commit 7c0ddbd into RIOT-OS:master Feb 27, 2022
@chrysn chrysn deleted the doc-flags-msgs branch February 27, 2022 20:11
@chrysn
Copy link
Member Author

chrysn commented Feb 27, 2022

Thank you!

Now that these semantics are clarified I can go ahead and send zero-sized types (like exclusive access to some globals) between threads on flags :-)

@OlegHahm OlegHahm added this to the Release 2022.04 milestone Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: core Area: RIOT kernel. Handle PRs marked with this with care! Area: doc Area: Documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: needs >1 ACK Integration Process: This PR requires more than one ACK Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants