Skip to content

Add util/atomic.h #350

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

Merged
merged 6 commits into from
Mar 19, 2023
Merged

Add util/atomic.h #350

merged 6 commits into from
Mar 19, 2023

Conversation

ghaug
Copy link
Contributor

@ghaug ghaug commented Mar 15, 2023

Hi,
I had the problem that I wanted to check a library modified by me which in turn includes a library that includes util/atomic.h and that doesn't work, of course. I added a mocked version of util/atomic.h, that simply does nothing. Atomicity by switching off interrupts is not possible on the host OS but timing behavior will differ anyway, therefore I think this approach is acceptable.
Best,
Gunter

@ianfixes
Copy link
Collaborator

Hi Gunter, thanks for submitting this!

Can you add (or just post here) a dummy/example usage of some atomic.h functions that we could refer to in a unit test? That way, we have a guard against future edits breaking things unexpectedly.

@ianfixes ianfixes added enhancement New feature or request arduino mocks Compilation mocks for the Arduino library labels Mar 15, 2023
@ghaug
Copy link
Contributor Author

ghaug commented Mar 15, 2023

Hi Ian,
thanks for the quick reply! There are two macros defined in atomic.h that can be used, namely ATOMIC_BLOCK and NONATOMIC_BLOCK. Each uses one of two parameters. An example would be:

ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
int a = callSomeFunction(para);
passToSomeOtherFunktion(a);
}

ATOMIC_BLOCK takes either ATOMIC_RESTORESTATE or ATOMIC_FORCEON as parameter, while NONATOMIC_BLOCK takes either NONATOMIC_RESTORESTATE or NONATOMIC_FORCEOFF, so there are just four combinations in total.

One more thing: Two of the checks fail for my pull request. I'm new to this project and I don't really know what's wrong.

@ghaug
Copy link
Contributor Author

ghaug commented Mar 17, 2023

Where would a unit test go? Would arduino_ci/SampleProjects/TestSomething/ be the right place?

@ianfixes
Copy link
Collaborator

Regarding the test failures, I think you can ignore the one with the linter -- it looks like a temporary problem with GitHub (and if not, I can look into it later). The only problem I'm seeing is a spelling error: https://github.com/Arduino-CI/arduino_ci/actions/runs/4424323994/jobs/7765538401?pr=350#step:4:19

Regarding a unit test, that would be awesome! Please call it something like atomic.cpp and put it in SampleProjects/TestSomething/test. For the format, just follow an example like the minimal ones shown in null.cpp or check the docs: https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md#most-basic-unit-test

@ghaug
Copy link
Contributor Author

ghaug commented Mar 18, 2023

I've added a unit test. As the macros don't do anything on the host, it just checks that all the four combinations compile without errors.

@ianfixes
Copy link
Collaborator

This is excellent, thank you!

@ianfixes ianfixes merged commit 4358f3a into Arduino-CI:master Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arduino mocks Compilation mocks for the Arduino library enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants