Skip to content

Rationalise Mail/Queue/MemoryPool timing APIs #12901

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 2 commits into from
May 12, 2020

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Apr 30, 2020

Summary of changes

Follow-up adjusting #12425 , improving (in my opinion, at least) the timing for Mail, Queue and MemoryPool. I think 12425 was too conservative at cleaning up the unsatisfactory state of their timing.

alloc APIs were generally inconsistent - take the opportunity to align with other APIs like Semaphore.

alloc -> try_alloc
alloc_for -> try_alloc_for
alloc_until -> try_alloc_until

In future the name alloc can be used for an untimed blocking allocation.

To line up with MemoryPool/Mail alloc, rework naming of get/put

Queue::get -> try_get, try_get_for
Queue::put -> try_put, try_put_for
Mail::get -> try_get, try_get_for
Mail::put (no change, but assert that it works)

In the future the names get and put can be used for untimed blocking operations. In the interim, you have to use try_get_for(Kernel::wait_for_u32_forever).

Mail::put differs in that it has always been a non-blocking call, but it can be assumed to always succeed when used correctly, because the Queue has enough room to store a pointer to every block in the MemoryPool. It could in future be made a void return, similar to the change made to Mutex::lock.

Impact of changes

Existing timing code will generate deprecation warnings, but there should be no functional change.

Migration actions required

Users should migrate to use Chrono-based APIs as directed by the deprecation messages

Documentation

None - all in Doxygen


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[X] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

This changes a couple of APIs just merged in #12425, but otherwise deprecates 5.15 ones, so I'm classing it as a feature change like that.


Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[X] Tests / results supplied as part of this PR

Reviewers


@kjbracey kjbracey requested a review from bulislaw April 30, 2020 10:02
@mergify mergify bot added the needs: work label Apr 30, 2020
@0xc0170 0xc0170 requested a review from a team May 4, 2020 11:35
@kjbracey
Copy link
Contributor Author

@bulislaw - ping - someone should really look at this, as its an incompatible API change to #12425. If no-one looks at it, you'll have to stick with that version.

@mbed-ci
Copy link

mbed-ci commented May 11, 2020

Test run: FAILED

Summary: 2 of 3 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-GCC_ARM
  • jenkins-ci/mbed-os-ci_build-ARM

@kjbracey
Copy link
Contributor Author

CI retriggered

@mbed-ci
Copy link

mbed-ci commented May 12, 2020

Test run: FAILED

Summary: 2 of 3 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM
  • jenkins-ci/mbed-os-ci_build-GCC_ARM

@kjbracey
Copy link
Contributor Author

Fixed thread test. Started CI.

@mbed-ci
Copy link

mbed-ci commented May 12, 2020

Test run: FAILED

Summary: 1 of 6 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

kjbracey added 2 commits May 12, 2020 15:17
alloc APIs were generally inconsistent - take the opportunity to align with
other APIs like Semaphore.

    alloc -> try_alloc
    alloc_for -> try_alloc_for
    alloc_until -> try_alloc_until

In future the name `alloc` can be used for an untimed blocking
allocation.
To line up with MemoryPool/Mail alloc, rework naming of get/put

    Queue::get -> try_get, try_get_for
    Queue::put -> try_put, try_put_for
    Mail::get -> try_get, try_get_for
    Mail::put (no change, but assert that it works)

In the future the names `get` and `put` can be used for untimed blocking
operations. In the interim, you have to use
`try_get_for(Kernel::wait_for_u32_forever)`.

`Mail::put` differs in that it has always been a non-blocking call, but
it can be assumed to always succeed when used correctly, because the
Queue has enough room to store a pointer to every block in the
MemoryPool. It could in future be made a `void` return, similar to the
change made to `Mutex::lock`.
@kjbracey
Copy link
Contributor Author

kjbracey commented May 12, 2020

Fixed Queue test. CI restarted

@mergify mergify bot added needs: CI and removed needs: work labels May 12, 2020
@mbed-ci
Copy link

mbed-ci commented May 12, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 4
Build artifacts

@0xc0170 0xc0170 merged commit 0b4b2af into ARMmbed:master May 12, 2020
@mergify mergify bot removed the ready for merge label May 12, 2020
{
osEvent evt = _queue.get(rel_time);
osEvent evt = _queue.get(millisec);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately the call to get will create a deprecation warning.

Copy link
Contributor Author

@kjbracey kjbracey May 13, 2020

Choose a reason for hiding this comment

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

Yes, but only when this deprecated Mail::get call is used, and this method is instantiated, because it's a templated class.

So it means 2 deprecation messages rather than 1, but none if you're not using a deprecated method.

I think.

If you do see a warning in a normal build, I'll revisit.

*/
MBED_DEPRECATED_SINCE("mbed-os-6.0.0", "Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`.")
osEvent get(uint32_t millisec)
MBED_DEPRECATED_SINCE("mbed-os-6.0.0", "Replaced with try_get and try_get_for. In future get will be an untimed blocking call.")
Copy link
Contributor

Choose a reason for hiding this comment

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

In the future the function signature should also change to take a T ** parameter

Copy link
Contributor Author

@kjbracey kjbracey May 13, 2020

Choose a reason for hiding this comment

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

The untimed get can actually just be T *get() - it can return it directly.

Would have been nice if try_get() could have returned T * itself, with nullptr return for failure, like try_alloc, but there's no rule saying people can't actually queue nullptr.

If we had std::optional<T *> or equivalent, could have returned that for try_get(). I did consider std::pair<T *, bool> return, which some std library APIs use, but figured it was too unconventional for Mbed OS. Although it is conceptually similar to the CMSIS RTOS 1 osEvent return it was using before. But structure returns like that usually end up less efficient for code size.

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

Successfully merging this pull request may close these issues.

5 participants