-
Notifications
You must be signed in to change notification settings - Fork 50
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
Revise scrotWaitUntil interface #323
Revise scrotWaitUntil interface #323
Conversation
This API could probably replace |
Hmm, hadn't thought about it but you're probably right. I'll try to do this tomorrow with a fresher mind. |
this will be useful for converting some of the nanosleep calls into scrotSleepFor().
absolute time is really awkward to use. scrotSleepFor() instead takes a starting timestamp and a relative millisecond offset from that start and returns back the ending timestamp. this, combined with clockNow(), makes the API easy to use and easy to replace the existing nanosleep calls with.
if (tmp.tv_nsec < 0) { | ||
tmp.tv_sec--; | ||
tmp.tv_nsec += 1000000000L; | ||
--tmp.tv_sec; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The webkit style guide doesn't say anything about preference toward pre vs post increments. And Ctrl+F "++" reveals many examples with both being used.
* correct for drift and call nanosleep() everywhere. | ||
*/ | ||
struct timespec ret; | ||
#if defined(__linux__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't think the CONTINUOUS_CLOCK
needed to be "public" anymore - since you can just use clockNow()
instead. So the ifdef
can be done internally for clockNow
.
(Though the main reason I added this function was to work around the awkwardness of clock_gettime
's outparam, e.g scrotSleepFor(clockNow(), 64)
is much easier to use.)
Hmm, using the interface as is to replace |
|
Ah, wait. |
If you provide a version of the function that takes a timespec, and then implement the one that uses milliseconds by calling the timespec version, we don't need the 24 day limit on |
Also, with 32-bit timespec (i.e. i386 glibc), it's possible to specify an int large enough to make struct timespec's tv_sec member overflow on master, if you write a timespec version, check for overflow. |
I think that energy is better spent on issues like #320 or feature requests like #82 that actually concerns scrot's primary purpose - to take screenshots. There's also too many other low hanging fruits with more practical issues (e.g #228) to be bothering with impractical things like 24 day+ delay. (Honestly this entire sleep saga to me seems like wasted effort fixing a non-issue that would've affected no-one.) |
avoids potential multiplication overflow when the seconds are converted into milliseconds.
The
timespec
argument for nanosleep is awkward because it usesns
when we want to sleep for somems
instead. AndscrotWaitUntil
is awkward because it uses absolute time, instead of relative time.Add
scrotWaitFor
which uses a relative time inms
and usesscrotWaitUntil
internally.CC: @guijan