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

Add timeout to acquireAndWait() method #3

Merged
merged 2 commits into from
Feb 7, 2016

Conversation

owendelong
Copy link
Contributor

The proposed changes implement a timeout argument to acquireAndWait() in a manner compatible with existing behavior of the library. If timeout=0 or no timeout is specified, default is to wait until acquisition finishes even if it never does.

If timeout is given a non-zero value, then the function will return when acquisition finishes or after timeout milliseconds, whichever occurs first. The timeout function is written in such a way that it should handle millis() counter wraps.

I've done basic testing of this code in my application and it appears to work.

Added support for millisecond timeout in acquireAndWait while preserving compatibility with 0-argument version of function.
Includes support for twos-compliment counter-wrap. (only supports one counter wrap, but since timeout is limited to uint32_t, specifying enough time to make more than one counter wrap is impossible anyway.

Since a millis() counter wrap in uint32_t is about 12 1/2 years, this should be adequate.
piettetech added a commit that referenced this pull request Feb 7, 2016
Add timeout to acquireAndWait() method
@piettetech piettetech merged commit f731da5 into piettetech:master Feb 7, 2016
@owendelong
Copy link
Contributor Author

Awesome… Thanks!!

Owen

On Feb 6, 2016, at 6:17 PM, Scott Piette [email protected] wrote:

Merged #3 #3.


Reply to this email directly or view it on GitHub #3 (comment).

@gusgonnet
Copy link

question, is it possible to publish this change in Particle's Build/library?
thanks!

@piettetech
Copy link
Owner

Hi, I wanted to test it but have not had the chance. Have you tested the
updated repository?

On Mon, Feb 15, 2016 at 5:53 AM, Gustavo [email protected] wrote:

question, is it possible to publish this change in Particle's
Build/library?
thanks!


Reply to this email directly or view it on GitHub
#3 (comment)
.

@gusgonnet
Copy link

alright, I'll give it a try and post back.
thanks

@gusgonnet
Copy link

Hi Scott,
I tried the new changes in two of my projects during the weekend and they are both running fine.
I'd suggest, but it's only a suggestion, that to avoid people experiencing the issues Owen fixed in this pull request, we modify the examples so they use acquireAndWait(5) instead of acquire()
what do you guys think?
thank you
Gustavo.

@piettetech
Copy link
Owner

Thanks Gustavo, Good suggestion, I can make the changes. I'm not able to
re-import my library and I am working with the Particle team to try and
correct that issue.

Scott

On Mon, Feb 22, 2016 at 5:18 AM, Gustavo [email protected] wrote:

Hi Scott,
I tried the new changes in two of my projects during the weekend and they
are both running fine.
I'd suggest, but it's only a suggestion, that to avoid people experiencing
the issues Owen fixed in this pull request, we modify the examples so they
use acquireAndWait(5) instead of acquire()
what do you guys think?
thank you
Gustavo.


Reply to this email directly or view it on GitHub
#3 (comment)
.

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.

3 participants